Sha256: 7430b8a66a2b081acc9faeeb638a4e7519ecd076c92de12fce1d7de627917d01

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

class Dhatu::Page < Dhatu::ApplicationRecord

  # Set Table Name
  self.table_name = "pages"

  # Including the State Machine Methods
  include Publishable

  # Validations
  validates :name, presence: true, length: {minimum: 3, maximum: 64}, allow_blank: false
  validates :code, presence: true, length: {minimum: 3, maximum: 64}, allow_blank: false
  
  # Associations
  belongs_to :feature, optional: true

  # Meta Tag Associations
  has_one :og_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::OgImage"
  has_many :meta_tags, :as => :meta_taggable, :dependent => :destroy, :class_name => "Dhatu::MetaTag"
  has_many :sections, class_name: "Dhatu::Section"
  
  # ------------------
  # Class Methods
  # ------------------

  scope :search, lambda { |query| where("LOWER(name) LIKE LOWER('%#{query}%') OR LOWER(code) LIKE LOWER('%#{query}%')") }

  # ------------------
  # Instance Methods
  # ------------------

  # Generic Methods
  # ---------------

  def display_name
    "#{self.name_was} - #{self.code}"
  end

  # Permission Methods
  # ------------------

  def can_be_edited?
    status?(:published) or status?(:unpublished)
  end

  def can_be_deleted?
    return false if self.sections.count > 0
    status?(:removed)
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dhatu-0.1.25 app/models/dhatu/page.rb
dhatu-0.1.24 app/models/dhatu/page.rb
dhatu-0.1.23 app/models/dhatu/page.rb
dhatu-0.1.22 app/models/dhatu/page.rb
dhatu-0.1.21 app/models/dhatu/page.rb
dhatu-0.1.20 app/models/dhatu/page.rb