class QME::MapReduce::Builder::Context

Utility class used to supply a binding to Erb

Public Class Methods

add_defaults(vars) click to toggle source

Add default parameter values if not specified

# File lib/qme/map/map_reduce_builder.rb, line 28
def self.add_defaults(vars)
  if !vars.has_key?('enable_logging')
    vars['enable_logging'] = false
  end
  if !vars.has_key?('enable_rationale')
    vars['enable_rationale'] = false
  end
  if !vars.has_key?('short_circuit')
    vars['short_circuit'] = false
  end
  vars
end
new(db, vars) click to toggle source

Create a new context @param [Hash] vars a hash of parameter names (String) and values (Object). Each entry is added as an accessor of the new Context

Calls superclass method
# File lib/qme/map/map_reduce_builder.rb, line 16
def initialize(db, vars)
  super(Context.add_defaults(vars))
  @db = db
end

Public Instance Methods

get_binding() click to toggle source

Get a binding that contains all the instance variables @return [Binding]

# File lib/qme/map/map_reduce_builder.rb, line 23
def get_binding
  binding
end
init_js_frameworks() click to toggle source

Inserts any library code into the measure JS. JS library code is loaded from three locations: the js directory of the quality-measure-engine project, the js sub-directory of the current directory (e.g. measures/js), and the bundles collection of the current database (used by the Rails Web application).

# File lib/qme/map/map_reduce_builder.rb, line 45
def init_js_frameworks
  result = ''
  result << 'if (typeof(map)=="undefined") {'
  result << "\n"
  @db['bundles'].find.each do |bundle|
    (bundle['extensions'] || []).each do |ext|
      result << "#{ext}();\n"
    end
  end
  result << "}\n"
  result
end