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 (I)
* prepare_to_validate stage (P2V)
* validate stage (V)
‘storage phase’
* prepare_to_store stage (P2S)
* store stage (S)
* finalize stage (F)
‘integration phase’
* integrate stage (IG)
* integrate_with_delay stage (IGwD)
Explanation:
yes! the recommended stage to do that
yes ok to do it here if necessary
no not recommended; chance to mess things up
but if something forces you to do it here you can try
no! never do it here. it won't work or will break things
if there is only a single entry in a phase column it counts for all stages of that phase
validation | storage | integrate
I P2V V | P2S S F | IG IGwD
add subcard yes! yes! yes | yes yes yes | yes remove subcard yes! yes! yes | yes no no! | no! validate yes yes yes! | no | no unsecure change yes yes! no | no! | no! secure change yes | yes! no! no! | no! abort yes! | yes | yes? fail create other cards has id no | no no? yes | yes dirty attributes yes | yes | no
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
88 89 90 |
# File 'lib/card/stage.rb', line 88 def after? allowed_phase STAGE_INDEX[allowed_phase] < STAGE_INDEX[stage] end |
#before?(allowed_phase) ⇒ Boolean
84 85 86 |
# File 'lib/card/stage.rb', line 84 def before? allowed_phase STAGE_INDEX[allowed_phase] > STAGE_INDEX[stage] end |
#in?(allowed_phase) ⇒ Boolean
92 93 94 95 |
# File 'lib/card/stage.rb', line 92 def in? allowed_phase (allowed_phase.is_a?(Array) && allowed_phase.include?(stage)) || allowed_phase == stage end |
#stage_index(stage) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/card/stage.rb', line 64 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
75 76 77 78 79 80 81 82 |
# File 'lib/card/stage.rb', line 75 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 |