Sha256: 1bb94be2f9173d9d651345bdd7d7fe45765e897b7f0ec58a8f0f387470593d37

Contents?: true

Size: 675 Bytes

Versions: 15

Compression:

Stored size: 675 Bytes

Contents

class MetaTag < ::ActiveRecord::Base
  belongs_to :taggable, :polymorphic => true
  
  validates_presence_of :name, :taggable_type
  validates_uniqueness_of :name, :scope => [:taggable_type, :taggable_id, :is_dynamic]
  
  attr_accessible :name, :content, :is_dynamic
  
  def get_content(controller=nil)
    self.is_dynamic ? dynamic_content(controller) : self.content
  end
  
  def dynamic_content(controller)
    self.content.gsub /%{([\w\.]+)}/ do
      items = $1.split('.')
      instance_name = items.shift
      method_name = items.join('.')
      record = controller.instance_variable_get("@#{instance_name}")

      record.try(:"#{method_name}")
    end
  end
end

Version data entries

15 entries across 11 versions & 2 rubygems

Version Path
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.6/app/models/meta_tag.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.5/app/models/meta_tag.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.5/app/models/meta_tag.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.6/app/models/meta_tag.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.6/app/models/meta_tag.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.5/app/models/meta_tag.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.6/app/models/meta_tag.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.5/app/models/meta_tag.rb
meta_manager-0.0.6 app/models/meta_tag.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/meta_manager-0.0.5/app/models/meta_tag.rb
meta_manager-0.0.5 app/models/meta_tag.rb
meta_manager-0.0.4 app/models/meta_tag.rb
meta_manager-0.0.3 app/models/meta_tag.rb
meta_manager-0.0.2 app/models/meta_tag.rb
meta_manager-0.0.1 app/models/meta_tag.rb