Module: ActsAsLiving::ScopesDefiner

Defined in:
lib/acts_as_living/scopes_definer.rb

Class Method Summary collapse

Class Method Details

.call(klass) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/acts_as_living/scopes_definer.rb', line 2

def self.call(klass)
  klass.class_eval do
    stage_keys.each do |stage|
      scope "past_#{stage}", -> { where('stage >= ?', stages_enum[stage]) }
      scope "pre_#{stage}", -> { where('stage < ?', stages_enum[stage]) }
    end

    scope :cancelled, -> { where('stage < 0') }

    phases.each do |phase, phase_stages|
      scope phase, lambda {
        phase_stages_integers = phase_stages.map { |stage| stages_enum[stage] }
        where(stage: phase_stages_integers)
      }
    end
  end
end