Class: ApiService::Base
- Inherits:
-
Object
- Object
- ApiService::Base
- Defined in:
- lib/api_service/base.rb
Class Method Summary collapse
- .actions ⇒ Object
- .add_action(name, options = {}, &action_body) ⇒ Object
- .add_shared_action(name, shared_action, options = {}) ⇒ Object
Instance Method Summary collapse
-
#initialize(params, initial_state = {}) ⇒ Base
constructor
A new instance of Base.
- #perform ⇒ Object
Constructor Details
#initialize(params, initial_state = {}) ⇒ Base
Returns a new instance of Base.
20 21 22 23 24 |
# File 'lib/api_service/base.rb', line 20 def initialize(params, initial_state = {}) @response = nil @params = params @state = ActionState.new(initial_state) end |
Class Method Details
.actions ⇒ Object
7 8 9 |
# File 'lib/api_service/base.rb', line 7 def actions @actions ||= [] end |
.add_action(name, options = {}, &action_body) ⇒ Object
15 16 17 |
# File 'lib/api_service/base.rb', line 15 def add_action(name, = {}, &action_body) actions << Action.new(name, , action_body) end |
.add_shared_action(name, shared_action, options = {}) ⇒ Object
11 12 13 |
# File 'lib/api_service/base.rb', line 11 def add_shared_action(name, shared_action, = {}) actions << shared_action.new(name, ) end |
Instance Method Details
#perform ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/api_service/base.rb', line 26 def perform actions_pool = self.class.actions actions_pool.each_with_index do |action, index| @state.add_current_action(action, index == actions_pool.size - 1) action.perform(@params, @state) if !@state.valid? && action.abort_on_fail? @state.build_failed_response break end end @state.response end |