module Reservable::ActsAsReservable::ClassMethods
Public Instance Methods
acts_as_reservable(**options)
click to toggle source
# File lib/reservable/acts_as_reservable.rb, line 9 def acts_as_reservable **options include Reservable::ActsAsReservable::LocalInstanceMethods has_many :reservations, as: :reservable, class_name: 'Reservable::Reservation' has_many :reservers, as: :reserver, through: :reservations accepts_nested_attributes_for :reservations, allow_destroy: true end
find_available(from, to, days)
click to toggle source
# File lib/reservable/acts_as_reservable.rb, line 19 def find_available(from, to, days) interval_ids = Reservable::Reservation.invervals_between(from, to, days).where('reservable_type = :class', class: self.name).map(&:reservable_id) edge_ids = Reservable::Reservation.edges_between(from, to, days).where('reservable_type = :class', class: self.name).map(&:reservable_id) missing_ids = self.includes(:reservations).where.not('reservable_reservations.reserved_on BETWEEN :from and :to', from: from, to: to).references(:reservations).pluck(:id) self.where(id: interval_ids + edge_ids + missing_ids) end