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
- #allowed_argument_error?(err, cmd, args) ⇒ Boolean
- #execute_command(cmd, args) ⇒ Object
- #init ⇒ Object
- #render_output(output) ⇒ Object
Instance Method Details
#allowed_argument_error?(err, cmd, args) ⇒ Boolean
239 240 241 |
# File 'lib/boson/science.rb', line 239 def allowed_argument_error?(err, cmd, args) err.class == OptionCommand::CommandArgumentError || super end |
#execute_command(cmd, args) ⇒ Object
243 244 245 |
# File 'lib/boson/science.rb', line 243 def execute_command(cmd, args) render_output super end |
#init ⇒ Object
225 226 227 228 |
# File 'lib/boson/science.rb', line 225 def init Command.all_option_commands = true if [:option_commands] super end |
#render_output(output) ⇒ Object
230 231 232 233 234 235 236 237 |
# File 'lib/boson/science.rb', line 230 def render_output(output) if (!Scientist.rendered && !View.silent_object?(output)) ^ [:render] ^ Boson.repo.config[:no_auto_render] opts = output.is_a?(String) ? {:method=>'puts'} : {:inspect=>!output.is_a?(Array) || (Scientist. || {})[:render] } View.render output, opts end end |