Module: Command::DSL::Formatting
- Included in:
- Action
- Defined in:
- lib/command-set/dsl.rb
Overview
The DSL for formatting. A lot of code will do just fine with the Kernel#puts #that Results intercepts. More involved output control starts by including CommandSet::DSL::Formatting, and using Formatting#list and Formatting#item to structure output for the formatters.
Instance Method Summary collapse
-
#begin_list(name, options = {}) ⇒ Object
Tells the main collector to begin a list.
-
#end_list ⇒ Object
Tells the main collector to end the current list.
-
#item(name, options = {}) ⇒ Object
Clean way to create an item of output.
-
#list(name, options = {}) ⇒ Object
To create lists and sublist of data, you can use #list to wrap code in a #begin_list / #end_list pair.
-
#sub_collector ⇒ Object
This returns a new Results::Collector, which can allow for some very sophisticated command output.
Instance Method Details
#begin_list(name, options = {}) ⇒ Object
Tells the main collector to begin a list. Subsequent output will be gathered into that list. For more, check out Results::Collector
405 406 407 |
# File 'lib/command-set/dsl.rb', line 405 def begin_list(name, ={}) @main_collector.begin_list(name, ) end |
#end_list ⇒ Object
Tells the main collector to end the current list. For more, check out Results::Collector
411 412 413 |
# File 'lib/command-set/dsl.rb', line 411 def end_list @main_collector.end_list end |
#item(name, options = {}) ⇒ Object
Clean way to create an item of output. Allows for various options to be added. The normal output method (#puts, #p, #write…) are all diverted within a command, and effectively create no-option items.
418 419 420 |
# File 'lib/command-set/dsl.rb', line 418 def item(name, ={}) @main_collector.item(name, ) end |
#list(name, options = {}) ⇒ Object
To create lists and sublist of data, you can use #list to wrap code in a #begin_list / #end_list pair.
397 398 399 400 401 |
# File 'lib/command-set/dsl.rb', line 397 def list(name, ={}) #:yield: begin_list(name, ) yield if block_given? end_list end |
#sub_collector ⇒ Object
This returns a new Results::Collector, which can allow for some very sophisticated command output. Specifically, it can allow a command to loop over a large amount of data once, depositing output in multiple lists at once, for instance a status list (with hashmarks) and results(with useful data) list.
427 428 429 |
# File 'lib/command-set/dsl.rb', line 427 def sub_collector @main_collector.dup end |