Module: Card::ActManager::Stage
- Included in:
- StageDirector
- Defined in:
- lib/card/act_manager/stage.rb
Constant Summary collapse
- STAGES =
[:initialize, :prepare_to_validate, :validate, :prepare_to_store, :store, :finalize, :integrate, :integrate_with_delay].freeze
- STAGE_INDEX =
stage_index.freeze
Instance Method Summary collapse
- #after?(allowed_phase) ⇒ Boolean
- #before?(allowed_phase) ⇒ Boolean
- #in?(allowed_phase) ⇒ Boolean
- #stage_index(stage) ⇒ Object
- #stage_ok?(opts) ⇒ Boolean
- #stage_symbol(index) ⇒ Object
Instance Method Details
#after?(allowed_phase) ⇒ Boolean
46 47 48 |
# File 'lib/card/act_manager/stage.rb', line 46 def after? allowed_phase STAGE_INDEX[allowed_phase] < STAGE_INDEX[stage] end |
#before?(allowed_phase) ⇒ Boolean
42 43 44 |
# File 'lib/card/act_manager/stage.rb', line 42 def before? allowed_phase STAGE_INDEX[allowed_phase] > STAGE_INDEX[stage] end |
#in?(allowed_phase) ⇒ Boolean
50 51 52 53 |
# File 'lib/card/act_manager/stage.rb', line 50 def in? allowed_phase (allowed_phase.is_a?(Array) && allowed_phase.include?(stage)) || allowed_phase == stage end |
#stage_index(stage) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/card/act_manager/stage.rb', line 22 def stage_index stage case stage when Symbol then return STAGE_INDEX[stage] when Integer then return stage else raise Card::Error, "not a valid stage: #{stage}" end end |
#stage_ok?(opts) ⇒ Boolean
33 34 35 36 37 38 39 40 |
# File 'lib/card/act_manager/stage.rb', line 33 def stage_ok? opts stage && ( (opts[:during] && in?(opts[:during])) || (opts[:before] && before?(opts[:before])) || (opts[:after] && after?(opts[:after])) || true # no phase restriction in opts ) end |
#stage_symbol(index) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/card/act_manager/stage.rb', line 12 def stage_symbol index case index when Symbol return index if STAGE_INDEX[index] when Integer return STAGES[index] if index < STAGES.size end raise Card::Error, "not a valid stage index: #{index}" end |