Module: DateBook::ActsAsEventOccurrence
- Defined in:
- lib/date_book/concerns/acts_as_event_occurrence.rb
Overview
Mixin to allow acts_as_event_occurrence behavior in EventOccurrence model
Defined Under Namespace
Modules: ClassMethods, InstanceMethods
Instance Method Summary collapse
-
#acts_as_event_occurrence(_options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
Instance Method Details
#acts_as_event_occurrence(_options = {}) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/date_book/concerns/acts_as_event_occurrence.rb', line 8 def acts_as_event_occurrence( = {}) before_save :set_end_date alias_attribute :start_date, :date belongs_to :schedulable, polymorphic: true alias_attribute :event, :schedulable delegate :schedule, to: :schedulable # Scopes scope :remaining, -> { where('date >= ?', Time.now) } scope :previous, -> { where('date < ?', Time.now) } scope :ending_after, (lambda do |start_date| (where 'end_date >= ?', start_date) end) scope :starting_before, ->(end_date) { where 'date < ?', end_date } scope :for_events, -> { where(schedulable_type: 'Event') } scope :for_schedulables, (lambda do |model_name, ids| where(schedulable_type: model_name).where('schedulable_id IN (?)', ids) end) scope :ascending, -> { order date: :asc } scope :descending, -> { order date: :desc } include InstanceMethods extend ClassMethods end |