Class: ApiService::ActionState
- Inherits:
-
Object
- Object
- ApiService::ActionState
- Defined in:
- lib/api_service/action_state.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #action ⇒ Object
- #add_current_action(action, is_last = false) ⇒ Object
- #build_failed_response ⇒ Object
- #errors ⇒ Object
- #fetch(field) ⇒ Object
-
#initialize(initial_state = {}) ⇒ ActionState
constructor
A new instance of ActionState.
- #set(field, value) ⇒ Object
- #success(response = {}, options = {}) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(initial_state = {}) ⇒ ActionState
Returns a new instance of ActionState.
9 10 11 12 13 |
# File 'lib/api_service/action_state.rb', line 9 def initialize(initial_state = {}) @response = nil @state = initial_state @error_manager = ErrorManager.new end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/api_service/action_state.rb', line 7 def response @response end |
Instance Method Details
#action ⇒ Object
20 21 22 |
# File 'lib/api_service/action_state.rb', line 20 def action @current_action end |
#add_current_action(action, is_last = false) ⇒ Object
15 16 17 18 |
# File 'lib/api_service/action_state.rb', line 15 def add_current_action(action, is_last = false) @current_action = action @is_current_action_last = is_last end |
#build_failed_response ⇒ Object
40 41 42 |
# File 'lib/api_service/action_state.rb', line 40 def build_failed_response @response = FailedResult.new(self) end |
#errors ⇒ Object
28 29 30 |
# File 'lib/api_service/action_state.rb', line 28 def errors @error_manager end |
#fetch(field) ⇒ Object
36 37 38 |
# File 'lib/api_service/action_state.rb', line 36 def fetch(field) @state[field] end |
#set(field, value) ⇒ Object
32 33 34 |
# File 'lib/api_service/action_state.rb', line 32 def set(field, value) @state[field] = value end |
#success(response = {}, options = {}) ⇒ Object
44 45 46 47 |
# File 'lib/api_service/action_state.rb', line 44 def success(response = {}, = {}) return unless @is_current_action_last @response = SuccessfulResult.new(response, self, ) end |
#valid? ⇒ Boolean
24 25 26 |
# File 'lib/api_service/action_state.rb', line 24 def valid? !errors.any? end |