Class: Wongi::Engine::DSL::Action::TraceAction

Inherits:
Base
  • Object
show all
Defined in:
lib/wongi-engine/dsl/action/trace_action.rb

Defined Under Namespace

Classes: DefaultTracer

Instance Attribute Summary collapse

Attributes inherited from Base

#name, #production, #rete, #rule

Instance Method Summary collapse

Methods included from CoreExt

included

Constructor Details

#initialize(opts = { }) ⇒ TraceAction

Returns a new instance of TraceAction.



24
25
26
27
28
29
30
31
32
33
# File 'lib/wongi-engine/dsl/action/trace_action.rb', line 24

def initialize opts = { }
  [:generation, :values, :tracer, :tracer_class, :io].each do |option|
    if opts.has_key? option
      instance_variable_set "@#{option}", opts[option]
    end
  end
  @io ||= $stdout
  @tracer ||= (@tracer_class || DefaultTracer).new
  @tracer.action = self
end

Instance Attribute Details

#ioObject (readonly)

Returns the value of attribute io.



21
22
23
# File 'lib/wongi-engine/dsl/action/trace_action.rb', line 21

def io
  @io
end

Instance Method Details

#execute(token) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/wongi-engine/dsl/action/trace_action.rb', line 39

def execute token
  production.tracer = self
  if values?
    trace action: self, token: token
  else
    trace action: self
  end
end

#trace(args) ⇒ Object



35
36
37
# File 'lib/wongi-engine/dsl/action/trace_action.rb', line 35

def trace args
  @tracer.trace args
end