Class: Injest::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/injest/middleware.rb

Constant Summary collapse

HEADERS_BLACKLIST =
%w[HTTP_COOKIE].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, processor: nil) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
10
11
12
13
14
# File 'lib/injest/middleware.rb', line 7

def initialize(app, processor: nil)
  @app = app
  init_configuration

  @processor = processor

  @subject = nil
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



4
5
6
# File 'lib/injest/middleware.rb', line 4

def configuration
  @configuration
end

#envObject (readonly)

Returns the value of attribute env.



5
6
7
# File 'lib/injest/middleware.rb', line 5

def env
  @env
end

#request_typeObject (readonly)

Returns the value of attribute request_type.



5
6
7
# File 'lib/injest/middleware.rb', line 5

def request_type
  @request_type
end

#subjectObject (readonly)

Returns the value of attribute subject.



5
6
7
# File 'lib/injest/middleware.rb', line 5

def subject
  @subject
end

Instance Method Details

#_call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/injest/middleware.rb', line 20

def _call(env)
  @env = env
  set_request_type
  return @app.call(env) unless trackable?

  @request_started_on = Time.now
  @status, @headers, @response = @app.call(env)
  @request_ended_on = Time.now

  set_subject

  data = build_data
  data = @processor.call(env, data) unless @processor.nil?

  append(data)

  [@status, @headers, @response]
end

#call(env) ⇒ Object



16
17
18
# File 'lib/injest/middleware.rb', line 16

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

#init_configurationObject



39
40
41
# File 'lib/injest/middleware.rb', line 39

def init_configuration
  @configuration = Injest::Configuration.instance
end