Module: Card::Stage
- Included in:
- StageDirector
- Defined in:
- lib/card/stage.rb
Overview
The process of writing a card change to the database is divided into 8 stages that are grouped in 3 phases.
‘validation phase’
* initialize stage
* prepare_to_validate stage
* validate stage
‘storage phase’
* prepare_to_store stage
* store stage
* finalize stage
‘integration phase’
* integrate stage
* integrate_with_delay stage
Constant Summary collapse
- STAGES =
[:initialize, :prepare_to_validate, :validate, :prepare_to_store, :store, :finalize, :integrate, :integrate_with_delay].freeze
- STAGE_INDEX =
{}
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
63 64 65 |
# File 'lib/card/stage.rb', line 63 def after? allowed_phase STAGE_INDEX[allowed_phase] < STAGE_INDEX[stage] end |
#before?(allowed_phase) ⇒ Boolean
59 60 61 |
# File 'lib/card/stage.rb', line 59 def before? allowed_phase STAGE_INDEX[allowed_phase] > STAGE_INDEX[stage] end |
#in?(allowed_phase) ⇒ Boolean
67 68 69 70 |
# File 'lib/card/stage.rb', line 67 def in? allowed_phase (allowed_phase.is_a?(Array) && allowed_phase.include?(stage)) || allowed_phase == stage end |
#stage_index(stage) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/card/stage.rb', line 39 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
50 51 52 53 54 55 56 57 |
# File 'lib/card/stage.rb', line 50 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 |