class ApiService::Base

Public Class Methods

actions() click to toggle source
# File lib/api_service/base.rb, line 7
def actions
  @actions ||= []
end
add_action(name, options = {}, &action_body) click to toggle source
# File lib/api_service/base.rb, line 15
def add_action(name, options = {}, &action_body)
  actions << Action.new(name, options, action_body)
end
add_shared_action(name, shared_action, options = {}) click to toggle source
# File lib/api_service/base.rb, line 11
def add_shared_action(name, shared_action, options = {})
  actions << shared_action.new(name, options)
end
new(params, initial_state = {}) click to toggle source
# File lib/api_service/base.rb, line 20
def initialize(params, initial_state = {})
  @response = nil
  @params = params
  @state = ActionState.new(initial_state)
end

Public Instance Methods

perform() click to toggle source
# 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