Module: Boson::BinRunner::Science

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

Overview

:render

Toggles the auto-rendering done for commands that don’t have views. Doesn’t affect commands that already have views. Default is false. Also see Auto Rendering section below.

Auto Rendering

Commands that don’t have views (defined via render_options) have their return value auto-rendered as a view as follows:

  • nil,false and true aren’t rendered

  • arrays are rendered with Hirb’s tables

  • non-arrays are printed with inspect()

  • Any of these cases can be toggled to render/not render with the global option :render

To turn off auto-rendering by default, add a :no_auto_render: true entry to the main config.

Instance Method Summary collapse

Instance Method Details

#allowed_argument_error?(err, cmd, args) ⇒ Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/boson/science.rb', line 247

def allowed_argument_error?(err, cmd, args)
  err.class == OptionCommand::CommandArgumentError || super
end

#execute_command(cmd, args) ⇒ Object



251
252
253
# File 'lib/boson/science.rb', line 251

def execute_command(cmd, args)
  render_output super
end

#initObject



233
234
235
236
# File 'lib/boson/science.rb', line 233

def init
  Command.all_option_commands = true if @options[:option_commands]
  super
end

#render_output(output) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/boson/science.rb', line 238

def render_output(output)
  if (!Scientist.rendered && !View.silent_object?(output)) ^ @options[:render] ^
    Boson.repo.config[:no_auto_render]
      opts = output.is_a?(String) ? {:method=>'puts'} :
        {:inspect=>!output.is_a?(Array) || (Scientist.global_options || {})[:render] }
      View.render output, opts
  end
end