Top Level Namespace

Defined Under Namespace

Modules: SeoMeta Classes: SeoMetaGenerator, SeoMetum

Instance Method Summary collapse

Instance Method Details

#is_seo_meta(options = {}) ⇒ Object


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

def is_seo_meta(options = {})
  if included_modules.exclude?(::SeoMeta::InstanceMethods)
    # Let the base know about SeoMetum
    has_one :seo_meta, :class_name => 'SeoMetum',
            :foreign_key => :seo_meta_id, :dependent => :destroy,
            :conditions => {:seo_meta_type => self.name}

    # 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