Sha256: b55fbb29c64daf9d49732a2427a0a6ec44b1b61d6d5bd08bb075ab66a298b0a5

Contents?: true

Size: 763 Bytes

Versions: 4

Compression:

Stored size: 763 Bytes

Contents

module MetaManager
  module Model
    extend ::ActiveSupport::Concern
    
    included do          
      validates_presence_of :name, :taggable_type, :content
      validates_uniqueness_of :name, :scope => [:taggable_type, :taggable_id, :is_dynamic]
      
      #attr_accessible :name, :content, :is_dynamic
    end
       
    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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
meta_manager-0.2.3 lib/meta_manager/model.rb
meta_manager-0.2.2 lib/meta_manager/model.rb
meta_manager-0.2.1 lib/meta_manager/model.rb
meta_manager-0.2.0 lib/meta_manager/model.rb