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



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

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

#default_pipe_optionsObject



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

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

#default_render_optionsObject



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

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

#delete_non_render_options(opt) ⇒ Object



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

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