Class: SimpleEndpoint::Endpoint

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/simple_endpoint/endpoint.rb,
lib/simple_endpoint/endpoint/endpoint_options.rb

Defined Under Namespace

Classes: EndpointOptions

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Endpoint

Returns a new instance of Endpoint.



15
16
17
# File 'lib/simple_endpoint/endpoint.rb', line 15

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/simple_endpoint/endpoint.rb', line 7

def options
  @options
end

Class Method Details

.call(options) ⇒ Object



11
12
13
# File 'lib/simple_endpoint/endpoint.rb', line 11

def self.call(options)
  new(options).call
end

Instance Method Details

#callObject



19
20
21
22
# File 'lib/simple_endpoint/endpoint.rb', line 19

def call
  procees_handler(before_response)
  procees_handler(handler, strict: true)
end

#matched_caseObject



24
25
26
27
# File 'lib/simple_endpoint/endpoint.rb', line 24

def matched_case
  @matched_case ||= cases.detect { |_kase, condition| invoker.instance_exec(result, &condition) }&.first
  @matched_case || raise(OperationIsNotHandled)
end

#procees_handler(handler, strict: false) ⇒ Object



29
30
31
32
# File 'lib/simple_endpoint/endpoint.rb', line 29

def procees_handler(handler, strict: false)
  return invoker.instance_exec(result, **renderer_options, &handler[matched_case]) if handler.key?(matched_case)
  raise UnhandledResultError.new(matched_case, handler) if strict
end