Class: BooticClient::ResponseHandlers::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/bootic_client/response_handlers.rb

Instance Method Summary collapse

Constructor Details

#initialize(handlers = []) ⇒ Set

Returns a new instance of Set.



6
7
8
# File 'lib/bootic_client/response_handlers.rb', line 6

def initialize(handlers = [])
  @handlers = handlers
end

Instance Method Details

#append(handler) ⇒ Object



21
22
23
# File 'lib/bootic_client/response_handlers.rb', line 21

def append(handler)
  @handlers << handler
end

#prepend(handler) ⇒ Object



25
26
27
# File 'lib/bootic_client/response_handlers.rb', line 25

def prepend(handler)
  @handlers.unshift handler
end

#resolve(response, client) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/bootic_client/response_handlers.rb', line 10

def resolve(response, client)
  custom = @handlers.find do |handler|
    obj = handler.call(response, client)
    break obj if obj
    nil
  end
  # if no handler found,
  # return raw Faraday response
  custom || response
end

#to_aObject



29
30
31
# File 'lib/bootic_client/response_handlers.rb', line 29

def to_a
  @handlers
end