Class: ActiveEndpoint::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/active_endpoint/proxy.rb

Instance Method Summary collapse

Constructor Details

#initializeProxy

Returns a new instance of Proxy.



3
4
5
6
7
8
# File 'lib/active_endpoint/proxy.rb', line 3

def initialize
  @created_at = Time.now
  @matcher = ActiveEndpoint::Routes::Matcher.new
  @logger = ActiveEndpoint.logger
  @notifier = ActiveSupport::Notifications
end

Instance Method Details

#track(env, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/active_endpoint/proxy.rb', line 10

def track(env, &block)
  request = ActiveEndpoint::Request.new(env)

  if ActiveEndpoint.log_debug_info
    @logger.debug('ActiveEndpoint::Blacklist', ActiveEndpoint.blacklist.inspect)
    @logger.debug('ActiveEndpoint::Constraints', ActiveEndpoint.constraints.inspect)
  end

  if @matcher.whitelisted?(request)
    track_begin(request)
    status, headers, response = yield block
    track_end(response)
    [status, headers, response]
  else
    register(request) if @matcher.unregistred?(request)

    yield block
  end
rescue => error
  @logger.error(self.class, error)

  yield block
end