class Smelter::ScriptRunner
Attributes
attributes[R]
context[R]
user[RW]
Public Class Methods
new()
click to toggle source
# File lib/smelter/script_runner.rb, line 7 def initialize @attributes = {} end
Public Instance Methods
load_registration(opts)
click to toggle source
# File lib/smelter/script_runner.rb, line 29 def load_registration(opts) opts[:klass].find_by(name: opts[:name]) end
method_missing(name, *args, &block)
click to toggle source
Calls superclass method
# File lib/smelter/script_runner.rb, line 33 def method_missing(name, *args, &block) if block_given? attributes[name.to_s] = block else attributes[name.to_s] = args[0] end rescue RuntimeError => e if !!e.message[/add a new key into hash during iteration/] super else raise e end end
run(instance={})
click to toggle source
# File lib/smelter/script_runner.rb, line 21 def run(instance={}) attributes.each do |attribute_name, value| result = value.is_a?(Proc) ? value.call(instance) : value instance[attribute_name.to_s] = result end instance end
set_context(context)
click to toggle source
# File lib/smelter/script_runner.rb, line 11 def set_context(context) @context = context attrs = @context.is_a?(Hash) ? @context.keys : @context.members attrs.each do |attr| self.define_singleton_method(attr) do @context[attr] end end end