module ActsAsBookable::Bookable

Private Class Methods

bookable?() click to toggle source
# File lib/acts_as_bookable/bookable.rb, line 39
def self.bookable?
  true
end

Public Instance Methods

acts_as_bookable(options={}) click to toggle source

Make a model bookable

Example:

class Room < ActiveRecord::Base
  acts_as_bookable
end
# File lib/acts_as_bookable/bookable.rb, line 15
def acts_as_bookable(options={})
  bookable(options)
end
bookable?() click to toggle source
# File lib/acts_as_bookable/bookable.rb, line 4
def bookable?
  false
end

Private Instance Methods

bookable(options) click to toggle source

Make a model bookable

# File lib/acts_as_bookable/bookable.rb, line 22
def bookable(options)

  if bookable?
    self.booking_opts = options
  else
    class_attribute :booking_opts
    self.booking_opts = options

    class_eval do
      serialize :schedule, IceCube::Schedule

      has_many :bookings, as: :bookable, dependent: :destroy, class_name: '::ActsAsBookable::Booking'

      validates_presence_of :schedule, if: :schedule_required?
      validates_presence_of :capacity, if: :capacity_required?
      validates_numericality_of :capacity, if: :capacity_required?, only_integer: true, greater_than_or_equal_to: 0

      def self.bookable?
        true
      end

      def schedule_required?
        self.booking_opts && self.booking_opts && self.booking_opts[:time_type] != :none
      end

      def capacity_required?
        self.booking_opts && self.booking_opts[:capacity_type] != :none
      end
    end
  end

  include Core
end
capacity_required?() click to toggle source
# File lib/acts_as_bookable/bookable.rb, line 47
def capacity_required?
  self.booking_opts && self.booking_opts[:capacity_type] != :none
end
schedule_required?() click to toggle source
# File lib/acts_as_bookable/bookable.rb, line 43
def schedule_required?
  self.booking_opts && self.booking_opts && self.booking_opts[:time_type] != :none
end