Module: ActiveRecord::Acts::Opengraph::ActMethods

Defined in:
lib/acts_as_opengraph/active_record/acts/opengraph.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_opengraph(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/acts_as_opengraph/active_record/acts/opengraph.rb', line 10

def acts_as_opengraph(options = {})
  # don't allow multiple calls
  return if included_modules.include? InstanceMethods
  
  extend ClassMethods
  
  opengraph_atts = %w(title type image url description site_name latitude longitude street_address locality region postal_code country_name email phone_number fax_number)
  
  options[:columns] ||= {}
  options[:values] ||= {}
  
  opengraph_atts.each do |att_name|
    options[:columns]["#{att_name}".to_sym] ||= alternative_column_name_for("og_#{att_name}".to_sym)
  end
  
  write_inheritable_attribute :opengraph_atts, opengraph_atts
  class_inheritable_reader :opengraph_atts
  
  write_inheritable_attribute :options, options
  class_inheritable_reader :options
  
  opengraph_atts.each do |att_name|
    define_method "opengraph_#{att_name}" do
      return_value_or_default att_name.to_sym
    end
  end
  
  include InstanceMethods
  
end