Sha256: ca8d6fd83b50f1acf2922953a7b55e210fb5c0c857136321fd28f1594944b9d5

Contents?: true

Size: 1.29 KB

Versions: 4

Compression:

Stored size: 1.29 KB

Contents

module Kuhsaft
  module PagePart
    class Content < ActiveRecord::Base
      belongs_to :localized_page      
      serialize :content
      
      class << self
        def serialize_attr name
          name = name.to_sym
          serializeable_attributes << name
          
          define_method name do
            self.content ||= {}
            self.content[name].presence
          end
          
          define_method "#{name}=" do |val|
            self.content_will_change!
            self.content ||= {}
            self.content[name] = val
          end
        end
        
        def searchable_attr name
          name = name.to_sym
          searchable_attributes << name
        end
        
        def searchable_attributes
          @searchable_attributes ||= []
        end

        def serializeable_attributes
          @serializeable_attributes ||= []
        end
        
        def page_part_types
          descendants
        end
        
        def to_name
          self.to_s.split('::').last
        end
      end
      
      private
      #
      # OMFG, OMFG!!! http://stackoverflow.com/questions/5178204/what-is-a-better-way-to-create-sti-model-instance
      #
      def atributes_protected_by_default
        super - [self.class.inheritance_column]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
kuhsaft-0.1.1 app/models/kuhsaft/page_part/content.rb
kuhsaft-0.1.0 app/models/kuhsaft/page_part/content.rb
kuhsaft-0.0.8 app/models/kuhsaft/page_part/content.rb
kuhsaft-0.0.7 app/models/kuhsaft/page_part/content.rb