Skip to content

Instantly share code, notes, and snippets.

@apraditya
Created October 5, 2012 08:00
Show Gist options
  • Save apraditya/3838667 to your computer and use it in GitHub Desktop.
Save apraditya/3838667 to your computer and use it in GitHub Desktop.
module OpengraphMethods
def og_site_name
"the site name"
end
#def og_title
# opengraph_from_method [:title, :full_name], use_postfix: true
#end
def og_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
class User < ActiveRecord::Base
include OpengraphMethods
acts_as_opengraph values: { type: 'movie'},
columns: { title: :og_title,
site_name: :og_site_name,
description: :og_description
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment