Top Level Namespace

Defined Under Namespace

Modules: SeoMeta Classes: SeoMetaGenerator, SeoMetum

Instance Method Summary collapse

Instance Method Details

#is_seo_meta(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/seo_meta.rb', line 21

def is_seo_meta(options = {})
  if included_modules.exclude?(::SeoMeta::InstanceMethods)
    # Let the base know about SeoMetum
    has_one_options = {
      :class_name => 'SeoMetum',
      :foreign_key => :seo_meta_id,
      :dependent => :destroy
    }.merge(options.slice(:class_name, :foreign_key, :dependent))

    if ActiveRecord::VERSION::STRING >= '4.0.0'
      has_one :seo_meta, proc { where(:seo_meta_type => self.name) }, has_one_options
    else
      has_one :seo_meta, {:conditions => {:seo_meta_type => self.name}}.merge(has_one_options)
    end

    # Let SeoMetum know about the base
    ::SeoMetum.send :belongs_to, self.name.underscore.gsub('/', '_').to_sym,
                    :class_name => self.name

    # Include the instance methods.
    self.send :include, ::SeoMeta::InstanceMethods

    # Ensure that seo_meta is saved after the model is saved.
    after_save :save_meta_tags!
  end

  # Delegate both the accessor and setters for the fields to :seo_meta
  fields = ::SeoMeta.attributes.keys.map{|a| [a, :"#{a}="]}.flatten

  fields << {:to => :seo_meta}
  delegate *fields
end