Sha256: cd6bc514578bb97656858ca7958845f3e02db8ce6be3e5e27cae57d37d5322d1

Contents?: true

Size: 884 Bytes

Versions: 6

Compression:

Stored size: 884 Bytes

Contents

class Section < ActiveRecord::Base
  extend ActiveSupport::Memoizable

  belongs_to :site, :inverse_of => :sections

  validates_presence_of :site, :name, :slug
  # validates_uniqueness_of :slug, :scope => [:site_id, :parent_id]

  has_slug :scope => :site_id
  acts_as_nested_set :scope => :site_id

  mattr_accessor :types
  self.types = []

  class << self
    def inherited(child)
      types << child.name
      super
    end

    def type_names
      @type_names ||= types.map(&:underscore)
    end
  end

  def type
    read_attribute(:type) || 'Page'
  end

  def path
    home? ? '' : super
  end

  def home?
    root? && previous_sibling.nil?
  end

  def attributes_protected_by_default
    default = [self.class.primary_key]
    default << 'id' unless self.class.primary_key.eql? 'id'
    default
  end

  protected

    def _path
      read_attribute(:path)
    end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
adva-core-0.0.9 app/models/section.rb
adva-core-0.0.8 app/models/section.rb
adva-core-0.0.7 app/models/section.rb
adva-core-0.0.6 app/models/section.rb
adva-core-0.0.5 app/models/section.rb
adva-core-0.0.4 app/models/section.rb