class LogStash::Filters::Ruby::Script::Context

Attributes

execution_context[R]
script[R]

Public Class Methods

new(script, parameters) click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 10
def initialize(script, parameters)
  @script = script
  @script_path = @script.script_path
  @parameters = parameters
  @test_contexts = []
  @script_lock = Mutex.new
  @concurrency = :single
end

Public Instance Methods

concurrency(type) click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 47
def concurrency(type)
  @concurrency = type
end
execute_filter(event) click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 51
def execute_filter(event)
  if @concurrency == :shared
    @script_lock.synchronize { @execution_context.filter(event) }
  else
    @execution_context.filter(event)
  end
end
execute_register() click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 43
def execute_register()
  @execution_context.register(@parameters)
end
execute_tests() click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 59
def execute_tests
  @test_contexts.
    map(&:execute).
    reduce({:passed => 0, :failed => 0, :errored => 0}) do |acc,res|
      acc[:passed] += res[:passed]
      acc[:failed] += res[:failed]
      acc[:errored] += res[:errored]
      acc
    end
end
load_execution_context(ec) click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 34
def load_execution_context(ec)
  ec.instance_eval(@script.content, @script_path, 1)
end
load_script() click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 38
def load_script
  @execution_context = self.make_execution_context(:main, false)
  load_execution_context(@execution_context)
end
make_execution_context(name, test_mode) click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 19
def make_execution_context(name, test_mode)
  execution_context = LogStash::Filters::Ruby::Script::ExecutionContext.new(name, logger)

  # Proxy all the methods from this instance needed to be run from the execution context
  this = self # We need to use a clojure to retain access to this object
  # If we aren't in test mode we define the test. If we *are* then we don't define anything
  # since our tests are already defined
  if test_mode
    execution_context.define_singleton_method(:test) {|name,&block| nil }
  else
    execution_context.define_singleton_method(:test) {|name,&block| this.test(name, &block) }
  end
  execution_context
end
test(name, &block) click to toggle source
# File lib/logstash/filters/ruby/script/context.rb, line 70
def test(name, &block)
  test_context = LogStash::Filters::Ruby::Script::TestContext.new(self, name)
  test_context.instance_eval(&block)
  @test_contexts << test_context
end