Module: Boson::Scientist::Render
- Included in:
- Boson::Scientist
- Defined in:
- lib/boson/science.rb
Overview
-
Before a method returns its value, it pipes its return value through pipe commands if pipe options are specified. See Pipe.
-
Methods can have any number of optional views associated with them via global render options (see View). Views can be toggled on/off with the global option –render (see OptionCommand).
Instance Attribute Summary collapse
-
#render ⇒ Object
Returns the value of attribute render.
-
#rendered ⇒ Object
Returns the value of attribute rendered.
Instance Method Summary collapse
- #after_parse ⇒ Object
- #can_render? ⇒ Boolean
- #command_renders? ⇒ Boolean
- #help_options ⇒ Object
- #process_result(result) ⇒ Object
- #run_pretend_option(args) ⇒ Object
Instance Attribute Details
#render ⇒ Object
Returns the value of attribute render.
118 119 120 |
# File 'lib/boson/science.rb', line 118 def render @render end |
#rendered ⇒ Object
Returns the value of attribute rendered.
118 119 120 |
# File 'lib/boson/science.rb', line 118 def rendered @rendered end |
Instance Method Details
#after_parse ⇒ Object
120 121 122 123 124 |
# File 'lib/boson/science.rb', line 120 def after_parse (@global_options[:delete_options] || []).map {|e| @global_options.keys.map {|k| k.to_s }.grep(/^#{e}/) }.flatten.each {|e| @global_options.delete(e.to_sym) } end |
#can_render? ⇒ Boolean
139 140 141 |
# File 'lib/boson/science.rb', line 139 def can_render? render.nil? ? command_renders? : render end |
#command_renders? ⇒ Boolean
143 144 145 |
# File 'lib/boson/science.rb', line 143 def command_renders? (!!@command. ^ @global_options[:render]) && !Pipe.any_no_render_pipes?(@global_options) end |
#help_options ⇒ Object
152 153 154 155 156 157 158 159 |
# File 'lib/boson/science.rb', line 152 def super.tap do |opts| if @global_options[:usage_options] opts << "--render_options=#{@global_options[:usage_options]}" end opts end end |
#process_result(result) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/boson/science.rb', line 126 def process_result(result) if (@rendered = can_render?) if @global_options.key?(:class) || @global_options.key?(:method) result = Pipe.scientist_process(result, @global_options, :config=>@command.config, :args=>@args, :options=>@current_options) end View.render(result, OptionCommand.(@global_options.dup), false) else Pipe.scientist_process(result, @global_options, :config=>@command.config, :args=>@args, :options=>@current_options) end rescue StandardError raise Scientist::Error, $!., $!.backtrace end |
#run_pretend_option(args) ⇒ Object
147 148 149 150 |
# File 'lib/boson/science.rb', line 147 def run_pretend_option(args) super @rendered = true if @global_options[:pretend] end |