Module: Boson::OptionCommand::ClassRender

Included in:
Boson::OptionCommand
Defined in:
lib/boson/science.rb

Overview

Adds render and pipe global options For more about pipe and render options see Pipe and View respectively.

Toggling Views With the Basic Global Option –render

One of the more important global options is –render. This option toggles the rendering of a command’s output done with View and Hirb.

Here’s a simple example of toggling Hirb’s table view:

 # Defined in a library file:
 #@options {}
 def list(options={})
   [1,2,3]
 end

 Using it in irb:
 >> list
 => [1,2,3]
 >> list '-r'  # or list --render
 +-------+
 | value |
 +-------+
 | 1     |
 | 2     |
 | 3     |
 +-------+
 3 rows in set
 => true
== Additional config keys for the main repo config
[:render_options] Hash of render options available to all option commands to be passed to a Hirb view (see View). Since

this merges with default render options, it’s possible to override default render options.

[:no_auto_render] When set, turns off commandline auto-rendering of a command's output. Default is false.

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



59
60
61
# File 'lib/boson/science.rb', line 59

def default_options
  default_pipe_options.merge(default_render_options.merge(BASIC_OPTIONS))
end

#default_pipe_optionsObject



63
64
65
# File 'lib/boson/science.rb', line 63

def default_pipe_options
  @default_pipe_options ||= PIPE_OPTIONS.merge Pipe.pipe_options
end

#default_render_optionsObject



67
68
69
# File 'lib/boson/science.rb', line 67

def default_render_options
  @default_render_options ||= RENDER_OPTIONS.merge Boson.repo.config[:render_options] || {}
end

#delete_non_render_options(opt) ⇒ Object



71
72
73
# File 'lib/boson/science.rb', line 71

def delete_non_render_options(opt)
  opt.delete_if {|k,v| BASIC_OPTIONS.keys.include?(k) }
end