Sha256: e2bdb6ec8415e8950d1bf08f2f8d8bd8ba0d8cf839b2d08dda214c965300cc8d

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8
module Freeberry
  module Models
    module Structure
      def self.included(base)
        base.send :include, InstanceMethods
        base.send :extend,  ClassMethods
      end
      
      module ClassMethods
        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
      end
      
      module InstanceMethods
        def moveable?
          return true if new_record?
          !root?
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
freeberry-0.3.0 lib/freeberry/models/structure.rb
freeberry-0.2.9 lib/freeberry/models/structure.rb
freeberry-0.2.7 lib/freeberry/models/structure.rb