Class: Tailog::Eval

Inherits:
Object
  • Object
show all
Defined in:
lib/tailog/eval.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Eval

Returns a new instance of Eval.



9
10
11
# File 'lib/tailog/eval.rb', line 9

def initialize app
  @app = app
end

Class Attribute Details

.blacklistObject

Returns the value of attribute blacklist.



4
5
6
# File 'lib/tailog/eval.rb', line 4

def blacklist
  @blacklist
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/tailog/eval.rb', line 13

def call env
  if skip_call? env
    @app.call(env)
  else
    before = env["HTTP_TAILOG_EVAL_BEFORE"].presence
    after = env["HTTP_TAILOG_EVAL_AFTER"].presence
    inject = env["HTTP_TAILOG_INJECT"].presence
    inject_options = env["HTTP_TAILOG_INJECT_OPTIONS"].present? ? JSON.parse(env["HTTP_TAILOG_INJECT_OPTIONS"]).symbolize_keys : Hash.new

    binding = Object.new.send(:binding)
    binding.eval(before) if before
    Tailog.inject(inject.split(" "), inject_options) rescue nil if inject

    response = @app.call(env)

    Tailog.cleanup(inject.split(" ")) if inject
    binding.eval(after) if after

    response
  end
end