Module: Card::Stage

Included in:
StageDirector
Defined in:
lib/card/stage.rb

Overview

available values: dirty attributes yes | yes | yes success yes | yes | yes no session yes | yes | yes no params yes | yes | yes

4) 'insecure' means a change of a card attribute that can possibly make the card invalid to save 5) 'secure' means you are sure that the change doesn't affect the validation

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

Instance Method Details

#after?(allowed_phase) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/card/stage.rb', line 97

def after? allowed_phase
  STAGE_INDEX[allowed_phase] < STAGE_INDEX[stage]
end

#before?(allowed_phase) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/card/stage.rb', line 93

def before? allowed_phase
  STAGE_INDEX[allowed_phase] > STAGE_INDEX[stage]
end

#in?(allowed_phase) ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
104
# File 'lib/card/stage.rb', line 101

def in? allowed_phase
  (allowed_phase.is_a?(Array) && allowed_phase.include?(stage)) ||
    allowed_phase == stage
end

#stage_index(stage) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/card/stage.rb', line 73

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

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
# File 'lib/card/stage.rb', line 84

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

Raises:



63
64
65
66
67
68
69
70
71
# File 'lib/card/stage.rb', line 63

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