Class: Wunderbar::TextBuilder

Inherits:
BuilderBase show all
Defined in:
lib/wunderbar/builder.rb

Instance Method Summary collapse

Methods inherited from BuilderBase

#get_binding, #set_variables_from_params

Constructor Details

#initialize(scope) ⇒ TextBuilder

Returns a new instance of TextBuilder.



241
242
243
244
# File 'lib/wunderbar/builder.rb', line 241

def initialize(scope)
  @_target = StringIO.new
  @_scope = scope
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

forward to Wunderbar, @_target, or @_scope



258
259
260
261
262
263
264
265
266
267
268
# File 'lib/wunderbar/builder.rb', line 258

def method_missing(method, *args, &block)
  if Wunderbar.respond_to? method
    return Wunderbar.send method, *args, &block
  elsif @_target.respond_to? method
    return @_target.send method, *args, &block
  elsif @_scope and @_scope.respond_to? method
    return @_scope.send method, *args, &block
  else
    super
  end
end

Instance Method Details

#_(*args) ⇒ Object



252
253
254
255
# File 'lib/wunderbar/builder.rb', line 252

def _(*args)
  @_target.puts *args if args.length > 0 
  self
end

#_exception(*args) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/wunderbar/builder.rb', line 270

def _exception(*args)
  exception = args.first
  if exception.respond_to? :backtrace
    Wunderbar.error exception.inspect
    @_target.puts unless size == 0
    @_target.puts exception.inspect
    exception.backtrace.each do |frame| 
      next if CALLERS_TO_IGNORE.any? {|re| frame =~ re}
      Wunderbar.warn "  #{frame}"
      @_target.puts "  #{frame}"
    end
  else
    super
  end
end

#encode(&block) ⇒ Object



246
247
248
249
250
# File 'lib/wunderbar/builder.rb', line 246

def encode(&block)
  set_variables_from_params
  self.instance_eval(&block)
  @_target.string
end

#target!Object



286
287
288
# File 'lib/wunderbar/builder.rb', line 286

def target!
  @_target.string
end