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.



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

def render
  @render
end

#renderedObject

Returns the value of attribute rendered.



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

def rendered
  @rendered
end

Instance Method Details

#after_parseObject



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

Returns:

  • (Boolean)


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

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

#command_renders?Boolean

Returns:

  • (Boolean)


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

def command_renders?
  (!!@command.render_options ^ @global_options[:render]) && !Pipe.any_no_render_pipes?(@global_options)
end

#help_optionsObject



152
153
154
155
156
157
158
159
# File 'lib/boson/science.rb', line 152

def help_options
  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.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



147
148
149
150
# File 'lib/boson/science.rb', line 147

def run_pretend_option(args)
  super
  @rendered = true if @global_options[:pretend]
end