class Booking
Public Class Methods
current()
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 28 def self.current where "starts_at >= ?", Date.today.beginning_of_day end
Public Instance Methods
to_s()
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 32 def to_s "#{self.name}" end
Private Instance Methods
perform_notification(notification_type)
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 65 def perform_notification(notification_type) ActiveSupport::Notifications.instrument("#{self.class.table_name.to_s.downcase}.#{notification_type}", :object => self) end
starts_in_future()
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 46 def starts_in_future if self.starts_at and self.starts_at < 15.minutes.from_now errors.add(:starts_at, 'must be at least 15 minutes from now') end end
timeslot_not_taken()
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 52 def timeslot_not_taken table_name = self.class.table_name if self.starts_at and self.ends_at if self.class.where("#{table_name}.starts_at <= ? AND #{table_name}.ends_at IS NULL OR #{table_name}.ends_at >= ?", self.starts_at, self.ends_at).any? errors.add(:base, "another #{self.class.to_s.downcase} has already been booked for the times you requested") end elsif self.starts_at if self.class.where("#{table_name}.starts_at <= ?", self.starts_at).any? errors.add(:base, "another #{self.class.to_s.downcase} has already been booked for the time you requested") end end end
update_booked_at()
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 38 def update_booked_at self.booked_at = Time.now end
update_cancelled_at()
click to toggle source
# File lib/bookings/generators/templates/booking_model.rb, line 42 def update_cancelled_at self.cancelled_at = Time.now end