Class: Wunderbar::TextBuilder
- Inherits:
-
BuilderClass
- Object
- BuilderBase
- BuilderClass
- Wunderbar::TextBuilder
- Defined in:
- lib/wunderbar/builder.rb
Instance Method Summary collapse
- #_(*args) ⇒ Object
- #_exception(*args) ⇒ Object
- #encode(&block) ⇒ Object
-
#initialize(scope) ⇒ TextBuilder
constructor
A new instance of TextBuilder.
-
#method_missing(method, *args, &block) ⇒ Object
forward to Wunderbar, @_target, or @_scope.
-
#system(command, opts = {}) ⇒ Object
execute a system command, echoing stdin, stdout, and stderr.
- #target! ⇒ Object
Methods inherited from BuilderClass
Methods inherited from BuilderBase
#get_binding, #set_variables_from_params
Constructor Details
#initialize(scope) ⇒ TextBuilder
Returns a new instance of TextBuilder.
379 380 381 382 |
# File 'lib/wunderbar/builder.rb', line 379 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
396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/wunderbar/builder.rb', line 396 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
390 391 392 393 |
# File 'lib/wunderbar/builder.rb', line 390 def _(*args) @_target.puts *args if args.length > 0 self end |
#_exception(*args) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/wunderbar/builder.rb', line 408 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
384 385 386 387 388 |
# File 'lib/wunderbar/builder.rb', line 384 def encode(&block) set_variables_from_params self.instance_eval(&block) @_target.string end |
#system(command, opts = {}) ⇒ Object
execute a system command, echoing stdin, stdout, and stderr
425 426 427 428 429 430 431 432 |
# File 'lib/wunderbar/builder.rb', line 425 def system(command, opts={}) output_prefix = opts[:prefix] || {} output_prefix[:stdin] ||= '$ ' super do |kind, line| @_target.puts "#{output_prefix[kind]}#{line}" end end |
#target! ⇒ Object
434 435 436 |
# File 'lib/wunderbar/builder.rb', line 434 def target! @_target.string end |