Sha256: 19a9b3b292846d85668734256fdb20c6b3ea937522b309d1c27c8234b30a3162

Contents?: true

Size: 1.3 KB

Versions: 11

Compression:

Stored size: 1.3 KB

Contents

class Dhatu::Booking < Dhatu::ApplicationRecord

  # Set Table Name
  self.table_name = "bookings"

  # Including the State Machine Methods
  include Readable
  include Featureable

  # Validations
  validates :name, presence: true, length: {minimum: 3, maximum: 256}, allow_blank: false
  # validate_email :email, mandatory: false, allow_blank: true
  validates :mobile, length: {maximum: 250}, allow_blank: true

  # Associations
  belongs_to :service
  
  # ------------------
  # Class Methods
  # ------------------

  scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR\
                                        LOWER(email) LIKE LOWER('%#{query}%') OR\
                                        LOWER(mobile) LIKE LOWER('%#{query}%') OR\
                                        LOWER(message) LIKE LOWER('%#{query}%')")}
  
  scope :upcoming, lambda { where("created_at >= ?", Time.now) }
  scope :past, lambda { where("created_at < ?", Time.now) }

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

  # Generic Methods
  # ---------------
  def to_param
    "#{id}-#{name.parameterize[0..32]}"
  end

  def display_name
    "#{name_was}"
  end

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

  def can_be_edited?
    false
  end

  def can_be_deleted?
    status?(:removed)
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dhatu-0.2.2 app/models/dhatu/booking.rb
dhatu-0.2.1 app/models/dhatu/booking.rb
dhatu-0.2.0 app/models/dhatu/booking.rb
dhatu-0.1.25 app/models/dhatu/booking.rb
dhatu-0.1.24 app/models/dhatu/booking.rb
dhatu-0.1.23 app/models/dhatu/booking.rb
dhatu-0.1.22 app/models/dhatu/booking.rb
dhatu-0.1.21 app/models/dhatu/booking.rb
dhatu-0.1.20 app/models/dhatu/booking.rb
dhatu-0.1.19 app/models/dhatu/booking.rb
dhatu-0.1.18 app/models/dhatu/booking.rb