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.



8
9
10
# File 'lib/bootic_client/response_handlers.rb', line 8

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

Instance Method Details

#append(handler) ⇒ Object



23
24
25
# File 'lib/bootic_client/response_handlers.rb', line 23

def append(handler)
  @handlers << handler
end

#prepend(handler) ⇒ Object



27
28
29
# File 'lib/bootic_client/response_handlers.rb', line 27

def prepend(handler)
  @handlers.unshift handler
end

#resolve(response, client) ⇒ Object



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

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



31
32
33
# File 'lib/bootic_client/response_handlers.rb', line 31

def to_a
  @handlers
end