Class: PaymentTest::State

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/payment_test/state.rb

Instance Method Summary collapse

Constructor Details

#initializeState

Returns a new instance of State.


8
9
10
# File 'lib/payment_test/state.rb', line 8

def initialize
  reset_configuration
end

Instance Method Details

#always_return_nil(method) ⇒ Object


93
94
95
# File 'lib/payment_test/state.rb', line 93

def always_return_nil(method)
  @always_return_nil && is_for_method(method)
end

#always_return_plugin_status_canceled(method) ⇒ Object


85
86
87
# File 'lib/payment_test/state.rb', line 85

def always_return_plugin_status_canceled(method)
  @always_return_plugin_status_canceled && is_for_method(method)
end

#always_return_plugin_status_error(method) ⇒ Object


77
78
79
# File 'lib/payment_test/state.rb', line 77

def always_return_plugin_status_error(method)
  @always_return_plugin_status_error && is_for_method(method)
end

#always_return_plugin_status_pending(method) ⇒ Object


81
82
83
# File 'lib/payment_test/state.rb', line 81

def always_return_plugin_status_pending(method)
  @always_return_plugin_status_pending && is_for_method(method)
end

#always_throw(method) ⇒ Object


89
90
91
# File 'lib/payment_test/state.rb', line 89

def always_throw(method)
  @always_throw && is_for_method(method)
end

#configure_always_return_plugin_status_canceled(methods = nil) ⇒ Object


26
27
28
29
30
31
# File 'lib/payment_test/state.rb', line 26

def configure_always_return_plugin_status_canceled(methods=nil)
  reset_configuration
  configure_methods(methods)
  @always_return_plugin_status_canceled = true
  log_current_state
end

#configure_always_return_plugin_status_error(methods = nil) ⇒ Object


19
20
21
22
23
24
# File 'lib/payment_test/state.rb', line 19

def configure_always_return_plugin_status_error(methods=nil)
  reset_configuration
  configure_methods(methods)
  @always_return_plugin_status_error = true
  log_current_state
end

#configure_always_return_plugin_status_pending(methods = nil) ⇒ Object


12
13
14
15
16
17
# File 'lib/payment_test/state.rb', line 12

def configure_always_return_plugin_status_pending(methods=nil)
  reset_configuration
  configure_methods(methods)
  @always_return_plugin_status_pending = true
  log_current_state
end

#configure_always_throw(methods = nil) ⇒ Object


33
34
35
36
37
38
# File 'lib/payment_test/state.rb', line 33

def configure_always_throw(methods=nil)
  reset_configuration
  configure_methods(methods)
  @always_throw = true
  log_current_state
end

#configure_return_nil(methods = nil) ⇒ Object


40
41
42
43
44
45
# File 'lib/payment_test/state.rb', line 40

def configure_return_nil(methods=nil)
  reset_configuration
  configure_methods(methods)
  @always_return_nil = true
  log_current_state
end

#configure_sleep_time(sleep_time_sec, methods = nil) ⇒ Object


47
48
49
50
51
52
# File 'lib/payment_test/state.rb', line 47

def configure_sleep_time(sleep_time_sec, methods=nil)
  reset_configuration
  configure_methods(methods)
  @sleep_time_sec = sleep_time_sec
  log_current_state
end

#is_clearObject


102
103
104
105
106
107
108
109
# File 'lib/payment_test/state.rb', line 102

def is_clear
  return !@always_return_plugin_status_error &&
      !@always_return_plugin_status_canceled &&
          !@always_return_plugin_status_pending &&
              !@always_throw &&
                  !@always_return_nil &&
                      @sleep_time_sec.nil?
end

#log_current_stateObject


111
112
113
# File 'lib/payment_test/state.rb', line 111

def log_current_state
  puts "PaymentTest:State : @always_return_plugin_status_error = #{@always_return_plugin_status_error}, @always_return_plugin_status_canceled = #{@always_return_plugin_status_canceled}, @always_return_plugin_status_pending=#{@always_return_plugin_status_pending}, @always_throw = #{@always_throw}, @always_return_nil = #{@always_return_nil}, @sleep_time_sec = #{@sleep_time_sec}, @methods=#{@methods}"
end

#reset_configurationObject


66
67
68
69
70
71
72
73
74
75
# File 'lib/payment_test/state.rb', line 66

def reset_configuration
  @always_return_plugin_status_error = false
  @always_return_plugin_status_pending = false
  @always_return_plugin_status_canceled = false
  @always_throw = false
  @always_return_nil = false
  @sleep_time_sec = nil
  @methods = nil
  log_current_state
end

#sleep_time_sec(method) ⇒ Object


97
98
99
100
# File 'lib/payment_test/state.rb', line 97

def sleep_time_sec(method)
  return @sleep_time_sec if @sleep_time_sec && is_for_method(method)
  nil
end

#statusObject


54
55
56
57
58
59
60
61
62
63
64
# File 'lib/payment_test/state.rb', line 54

def status
  {
   :always_return_plugin_status_error => @always_return_plugin_status_error,
   :always_return_plugin_status_pending => @always_return_plugin_status_pending,
   :always_return_plugin_status_canceled => @always_return_plugin_status_canceled,
   :always_throw => @always_throw,
   :always_return_nil => @always_return_nil,
   :sleep_time_sec => @sleep_time_sec,
   :methods => @methods
  }
end