Module: Freeberry::Models::Structure::ClassMethods

Defined in:
lib/freeberry/models/structure.rb

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/freeberry/models/structure.rb', line 11

def self.extended(base)
  base.send(:include, HeaderUtils)
  base.class_eval do
    enumerated_attribute :structure_type, :id_attribute => :kind
    enumerated_attribute :position_type, :id_attribute => :position
    
    validates_presence_of :title
    validates_numericality_of :position, :only_integer => true
    
    has_one :page, :dependent => :destroy
    has_many :posts, :dependent => :destroy
    
    scope :visible, where(:is_visible => true)
    scope :with_kind, proc {|structure_type| where(:kind => structure_type.id) }
    scope :with_depth, proc {|level| where(:depth => level.to_i) }
    scope :with_position, proc {|position_type| where(:position => position_type.id) }
  end
end