Sha256: f68c7bb6dc4ee19436c784e535e90e797da4031861d3be9df7f19fec58b5b97b

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

class Dhatu::Event < Dhatu::ApplicationRecord

  # Set Table Name
  self.table_name = "events"

  # Including the State Machine Methods
  include Publishable
  include Featureable

  # Validations
  validates :title, presence: true, length: {minimum: 5, maximum: 500}, allow_blank: false
  validates :venue, length: {minimum: 3, maximum: 250}, allow_blank: true
  validates :description, presence: true

  # Associations
  belongs_to :category
  has_one :cover_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CoverImage"
  has_many :gallery_images, :as => :imageable, :dependent => :destroy, :class_name => "Image::GalleryImage"
  
  # ------------------
  # Class Methods
  # ------------------

  scope :search, lambda { |query| where("LOWER(title) LIKE LOWER('%#{query}%') OR\
                                        LOWER(venue) LIKE LOWER('%#{query}%') OR\
                                        LOWER(description) LIKE LOWER('%#{query}%')") }

  scope :upcoming, lambda { where("starts_at >= ?", Time.now) }
  scope :past, lambda { where("starts_at < ?", Time.now) }
  
  # ------------------
  # Instance Methods
  # ------------------

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

  def to_param
    "#{id}-#{title.parameterize[0..32]}"
  end

  def display_name
    "#{title_was}"
  end

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

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

  def can_be_deleted?
    status?(:removed)
  end
  
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dhatu-0.1.10 app/models/dhatu/event.rb
dhatu-0.1.9 app/models/dhatu/event.rb
dhatu-0.1.8 app/models/dhatu/event.rb
dhatu-0.1.7 app/models/dhatu/event.rb
dhatu-0.1.6 app/models/dhatu/event.rb