Sha256: 64c3172da627b7f13b2b1bcbc9732f31d8f40234608ba84f9b83f74b8fe9bb98

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

class Section
  include LuckySneaks::StringExtensions
  include Mongoid::Document
  include Mongoid::Timestamps

  # Mongo Config ===================================================================================
  field :headline
  field :slug
  field :content
  field :summary
  field :position, :type => Integer
  field :related_contents, :type => Array, :default => []
  index :slug, :unique => true
  index :state, :unique => false
  embedded_in :managed_content, :inverse_of => :sections

  # Behavior =======================================================================================
  before_save :set_slug
  validates_presence_of :content, :headline
  validates_uniqueness_of :slug

  # Instance methods ===============================================================================

  # @deprecated Please use {#path} instead
  def humanize_path
    warn "[DEPRECATION] `humanize_path` is deprecated.  Please use `path` instead."
    self.path
  end

  def next_section
    self.managed_content.sections.where(:position => self.position + 1).first
  end

  def path
    self.position == 1 ? self.managed_content.path : "#{self.managed_content.path}/#{self.slug}"
  end

  def siblings
    self.managed_content.sections.sort{|a,b| a.position.to_i <=> b.position.to_i}
  end

  private

  def set_slug
    self.slug = self.headline.to_s.to_url if self.slug.blank?
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
editorial_logic-1.4.4 app/models/section.rb
editorial_logic-1.4.3 app/models/section.rb
editorial_logic-1.4.2 app/models/section.rb
editorial_logic-1.4.1 app/models/section.rb
editorial_logic-1.4.0 app/models/section.rb