Class: Wongi::Engine::TraceAction

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

Defined Under Namespace

Classes: DefaultTracer

Instance Attribute Summary collapse

Attributes inherited from Action

#name, #production, #rete, #rule

Instance Method Summary collapse

Methods included from CoreExt

included

Constructor Details

#initialize(opts = { }) ⇒ TraceAction

Returns a new instance of TraceAction.



26
27
28
29
30
31
32
33
34
35
# File 'lib/wongi-engine/dsl/actions/trace_action.rb', line 26

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.



23
24
25
# File 'lib/wongi-engine/dsl/actions/trace_action.rb', line 23

def io
  @io
end

Instance Method Details

#execute(token) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/wongi-engine/dsl/actions/trace_action.rb', line 41

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

#trace(args) ⇒ Object



37
38
39
# File 'lib/wongi-engine/dsl/actions/trace_action.rb', line 37

def trace args
  @tracer.trace args
end