Skip to content

Instantly share code, notes, and snippets.

@apraditya
Created September 28, 2012 08:46
Show Gist options
  • Save apraditya/3798700 to your computer and use it in GitHub Desktop.
Save apraditya/3798700 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
include OpengraphMethods
def opengraph_title
opengraph_site_name # doesn't create the meta entry
# These don't create as well
send(:opengraph_site_name)
send(:opengraph_site_name).to_s
'this one works'
end
end
module OpengraphMethods
def opengraph_site_name
"TAI"
end
#def opengraph_title
# opengraph_from_method [:title, :full_name], use_postfix: true
#end
def opengraph_description
opengraph_from_method [:logline_text, :about_me]
end
private
def opengraph_from_method(possible_methods, options={})
default_options = {default_text: DEFAULT_TEXT, use_postfix: false}
options.reverse_merge! default_options
attribute_value = possible_methods.each do |method|
break send(method) if respond_to?(method)
end
if attribute_value.blank?
options[:default_text]
elsif options[:use_postfix]
"#{attribute_value} | #{options[:default_text]}"
else
attribute_value
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment