Module: Hirb::Console

Defined in:
lib/hirb/console.rb

Overview

This module is meant to be extended to provide methods for use in a console/irb shell. For example:

irb>> extend Hirb::Console
irb>> view 'some string', :class=>Some::String::Formatter
irb>> table [[:row1], [:row2]]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.format_output(output, options = {}, &block) ⇒ Object

Takes same arguments and options as render_output() but returns formatted output instead of rendering it.



22
23
24
25
# File 'lib/hirb/console.rb', line 22

def format_output(output, options={}, &block)
  View.load_config unless View.config_loaded?
  View.formatter.format_output(output, options.merge(:console=>true), &block)
end

.render_output(output, options = {}) ⇒ Object

A console version of render_output() which takes its same options but allows for shorthand. All options are passed to the helper except for the formatter options. Formatter options are :class, :method and :output_method. Examples:

render_output output, :class=>:tree :type=>:directory
# is the same as:
render_output output, :class=>:tree, :options=> {:type=>:directory}


16
17
18
19
# File 'lib/hirb/console.rb', line 16

def render_output(output, options={})
  View.load_config unless View.config_loaded?
  View.render_output(output, options.merge(:console=>true))
end

Instance Method Details

Renders a menu given an array using Hirb::Menu.render.



39
40
41
# File 'lib/hirb/console.rb', line 39

def menu(output, options={}, &block)
  Console.format_output(output, options.merge(:class=>"Hirb::Menu"), &block)
end

#table(output, options = {}) ⇒ Object

Renders a table for the given object. Takes same options as Hirb::Helpers::Table.render.



29
30
31
# File 'lib/hirb/console.rb', line 29

def table(output, options={})
  Console.render_output(output, options.merge(:class=>"Hirb::Helpers::AutoTable"))
end

#view(output, options = {}) ⇒ Object

Renders any specified view for the given object. Takes same options as Hirb::View.render_output.



34
35
36
# File 'lib/hirb/console.rb', line 34

def view(output, options={})
  Console.render_output(output, options)
end