Class: MetOnTheMiddle::RootMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/met_on_the_middle/root_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RootMiddleware

Returns a new instance of RootMiddleware.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/met_on_the_middle/root_middleware.rb', line 7

def initialize(app)
  @app = app

  generate_tracker

  if defined?(PhusionPassenger)
    PhusionPassenger.on_event(:starting_worker_process) do |forked|
      if forked
        generate_tracker
      end
    end
  end

end

Instance Attribute Details

#trackerObject (readonly)

Returns the value of attribute tracker.



5
6
7
# File 'lib/met_on_the_middle/root_middleware.rb', line 5

def tracker
  @tracker
end

Instance Method Details

#_call(env) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/met_on_the_middle/root_middleware.rb', line 40

def _call(env)
  response = nil

  @tracker.request_block do

    ActiveSupport::Notifications.instrument "met_on_the_middle.total_time" do
      response = @app.call(env)
    end

  end


  response
end

#call(env) ⇒ Object

Serve per essere multy trade safe



36
37
38
# File 'lib/met_on_the_middle/root_middleware.rb', line 36

def call(env)
  dup._call(env)
end

#generate_trackerObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/met_on_the_middle/root_middleware.rb', line 22

def generate_tracker
  @tracker = Tracker.new(MetOnTheMiddle.configuration)
  @tracker.start!

  ##
  # TODO trovare sistema migliore per individuare se siamo lanciati tramite
  # rake oppure tramite server
  unless File.basename($0) == 'rake'
    register_subscriptions
  end
end

#register_subscriptionsObject



56
57
58
59
60
# File 'lib/met_on_the_middle/root_middleware.rb', line 56

def register_subscriptions
  MetOnTheMiddle.configuration.readers.each do |r|
    r.register_subscription(@tracker)
  end
end