Sha256: a3524ff7560ceedbcf78aef0fd96f9027be825015202f291063aa96d407e9ff5
Contents?: true
Size: 1.46 KB
Versions: 13
Compression:
Stored size: 1.46 KB
Contents
class Card class ActManager module Stage STAGES = %i[initialize prepare_to_validate validate prepare_to_store store finalize integrate after_integrate integrate_with_delay].freeze stage_index = {} STAGES.each_with_index do |stage, i| stage_index[stage] = i end STAGE_INDEX = stage_index.freeze 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 def stage_index stage case stage when Symbol then STAGE_INDEX[stage] when Integer then stage else raise Card::Error, "not a valid stage: #{stage}" end end 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 def before? allowed_phase STAGE_INDEX[allowed_phase] > STAGE_INDEX[stage] end def after? allowed_phase STAGE_INDEX[allowed_phase] < STAGE_INDEX[stage] end def in? allowed_phase (allowed_phase.is_a?(Array) && allowed_phase.include?(stage)) || allowed_phase == stage end end end end
Version data entries
13 entries across 13 versions & 1 rubygems