Class: Amrita2::Core::Template::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/amrita2/template.rb

Instance Method Summary collapse

Constructor Details

#initialize(io_or_type, &block) ⇒ Tracer

Returns a new instance of Tracer.



1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
# File 'lib/amrita2/template.rb', line 1279

def initialize(io_or_type, &block)
  @auto_trace = false
  @trace_proc = block
  case io_or_type
  when :code, :element, :all
    @type = io_or_type
    raise "need block" unless @trace_proc
  when :all_element
    @type = :element
    @auto_trace = true
    raise "need block" unless @trace_proc
  else
    if io_or_type.respond_to?(:<<)
      @type = :all
      @auto_trace = true
      @trace_proc = proc do |msg|
        io_or_type << msg << "\n"
      end
    else
      raise "unknown type for trace #{io_or_type.inspect}"
    end
  end
end

Instance Method Details

#<<(msg) ⇒ Object



1315
1316
1317
# File 'lib/amrita2/template.rb', line 1315

def <<(msg)
  @trace_proc.call(msg) if @type == :all or @type == :element
end

#auto_trace?Boolean

Returns:

  • (Boolean)


1303
1304
1305
# File 'lib/amrita2/template.rb', line 1303

def auto_trace?
  @auto_trace
end

#code(cg) ⇒ Object



1311
1312
1313
# File 'lib/amrita2/template.rb', line 1311

def code(cg)
  @trace_proc.call(cg.result) if code_trace?
end

#code_trace?Boolean

Returns:

  • (Boolean)


1307
1308
1309
# File 'lib/amrita2/template.rb', line 1307

def code_trace?
  @type == :code or @type == :all
end