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

Instance Method Summary collapse

Instance Attribute Details

#renderObject

Returns the value of attribute render.



119
120
121
# File 'lib/boson/science.rb', line 119

def render
  @render
end

#renderedObject

Returns the value of attribute rendered.



119
120
121
# File 'lib/boson/science.rb', line 119

def rendered
  @rendered
end

Instance Method Details

#after_parseObject



121
122
123
124
125
# File 'lib/boson/science.rb', line 121

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

Returns:

  • (Boolean)


140
141
142
# File 'lib/boson/science.rb', line 140

def can_render?
  render.nil? ? command_renders? : render
end

#command_renders?Boolean

Returns:

  • (Boolean)


144
145
146
# File 'lib/boson/science.rb', line 144

def command_renders?
  (!!@command.render_options ^ @global_options[:render]) && !Pipe.any_no_render_pipes?(@global_options)
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 @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.delete_non_render_options(@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, $!.message, $!.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 @global_options[:pretend]
end