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
- #process_result(result) ⇒ Object
- #run_pretend_option(args) ⇒ Object
Instance Attribute Details
#render ⇒ Object
Returns the value of attribute render.
119 120 121 |
# File 'lib/boson/science.rb', line 119 def render @render end |
#rendered ⇒ Object
Returns the value of attribute rendered.
119 120 121 |
# File 'lib/boson/science.rb', line 119 def rendered @rendered end |
Instance Method Details
#after_parse ⇒ Object
121 122 123 124 125 |
# File 'lib/boson/science.rb', line 121 def after_parse ([:delete_options] || []).map {|e| .keys.map {|k| k.to_s }.grep(/^#{e}/) }.flatten.each {|e| .delete(e.to_sym) } end |
#can_render? ⇒ Boolean
140 141 142 |
# File 'lib/boson/science.rb', line 140 def can_render? render.nil? ? command_renders? : render end |
#command_renders? ⇒ Boolean
144 145 146 |
# File 'lib/boson/science.rb', line 144 def command_renders? (!!@command. ^ [:render]) && !Pipe.any_no_render_pipes?() end |
#process_result(result) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/boson/science.rb', line 127 def process_result(result) if (@rendered = can_render?) if .key?(:class) || .key?(:method) result = Pipe.scientist_process(result, , :config=>@command.config, :args=>@args, :options=>) end View.render(result, OptionCommand.(.dup), false) else Pipe.scientist_process(result, , :config=>@command.config, :args=>@args, :options=>) end rescue StandardError raise Scientist::Error, $!., $!.backtrace end |
#run_pretend_option(args) ⇒ Object
148 149 150 151 |
# File 'lib/boson/science.rb', line 148 def run_pretend_option(args) super @rendered = true if [:pretend] end |