Module: EndpointFlux::Endpoint

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *attrs, &block) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/endpoint_flux/endpoint.rb', line 32

def method_missing(method_id, *attrs, &block)
  method_sym = method_id.to_sym
  if flow.include?(method_sym)
    configure_middleware(method_sym, attrs, &block)
  else
    super
  end
end

Class Method Details

.included(includer) ⇒ Object



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

def self.included(includer)
  includer.extend self
  includer.class_eval %( @middlewares ||= {} )
end

Instance Method Details

#flow(array = nil) ⇒ Object



27
28
29
30
# File 'lib/endpoint_flux/endpoint.rb', line 27

def flow(array = nil)
  @flow = array.map(&:to_sym) if array
  @flow || EndpointFlux.config.flow
end

#perform(request) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/endpoint_flux/endpoint.rb', line 12

def perform(request)
  attrs = [request, EndpointFlux::Response.new]
  attrs = EndpointFlux.config.interceptor.run(attrs)

  request.endpoint = to_s

  flow.inject(attrs) do |res, middleware_name|
    fetch_middleware(middleware_name).inject(res) do |middleware_res, middleware|
      middleware.run(middleware_res)
    end
  end
rescue *EndpointFlux.config.rescue_from.exceptions => e
  EndpointFlux.config.rescue_from.run(name, attrs, e)
end

#respond_to_missing?(method_name) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/endpoint_flux/endpoint.rb', line 41

def respond_to_missing?(method_name)
  flow.include?(method_name.to_sym)
end