class Jerry::ClassProvider
A provider that instanciates a given class by collecting constructor arguments through a given jerry instance.
Public Class Methods
new(klass, args_spec)
click to toggle source
@param klass [Class] class to be instanciated @param args_spec [Array<Clsss, Symbol, Proc>] specification for the
constructor arguments. Classes and Symbols are used to collect the arguments from the jerry instance. Procs are called to generate arguments.
# File lib/jerry/class_provider.rb, line 10 def initialize(klass, args_spec) @klass = klass @args_spec = args_spec end
Public Instance Methods
call(jerry, config)
click to toggle source
@param jerry [Jerry] a jerry instance @param config [Jerry::Config] the config holding the provider @return An instance of the class given in the constructor
# File lib/jerry/class_provider.rb, line 18 def call(jerry, config) args = @args_spec.map do |spec| if spec.respond_to? :call config.instance_exec(jerry, config, &spec) else jerry[spec] end end @klass.new(*args) end