Sha256: 3182b2f9f7854cd8802aec9bfe28dc103a1b3b8b6cb9b5b0d21bcd9bda913556

Contents?: true

Size: 1023 Bytes

Versions: 24

Compression:

Stored size: 1023 Bytes

Contents

module Tailog
  class Eval
    class << self
      attr_accessor :blacklist
    end

    self.blacklist = %w(/tailog)

    def initialize app
      @app = app
    end

    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

    private

    def skip_call? env
      Tailog::Eval.blacklist.any? do |path|
        env["PATH_INFO"].start_with? path
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
tailog-0.7.0 lib/tailog/eval.rb
tailog-0.6.9 lib/tailog/eval.rb
tailog-0.6.8 lib/tailog/eval.rb
tailog-0.6.7 lib/tailog/eval.rb
tailog-0.6.6 lib/tailog/eval.rb
tailog-0.6.5 lib/tailog/eval.rb
tailog-0.6.4 lib/tailog/eval.rb
tailog-0.6.3 lib/tailog/eval.rb
tailog-0.6.2 lib/tailog/eval.rb
tailog-0.6.1 lib/tailog/eval.rb
tailog-0.6.0 lib/tailog/eval.rb
tailog-0.5.9 lib/tailog/eval.rb
tailog-0.5.8 lib/tailog/eval.rb
tailog-0.5.7 lib/tailog/eval.rb
tailog-0.5.6 lib/tailog/eval.rb
tailog-0.5.5 lib/tailog/eval.rb
tailog-0.5.4 lib/tailog/eval.rb
tailog-0.5.2 lib/tailog/eval.rb
tailog-0.5.1 lib/tailog/eval.rb
tailog-0.5.0 lib/tailog/eval.rb