Class: Blueprints::EvalContext
- Inherits:
-
Object
- Object
- Blueprints::EvalContext
- Defined in:
- lib/blueprints/eval_context.rb
Instance Method Summary collapse
-
#build(*blueprints) ⇒ Object
Builds blueprints by delegating to root namespace.
-
#copy_instance_variables(target) ⇒ Object
Copy instance variables to another object.
-
#instance_eval(context, options, &block) ⇒ Object
Sets options and attributes and evaluates block against self.
-
#normalize_hash(hash) ⇒ Hash
Normalizes attributes hash by evaluating all Proc and Blueprints::Dependency objects against itself.
Instance Method Details
#build(*blueprints) ⇒ Object
Builds blueprints by delegating to root namespace.
26 27 28 |
# File 'lib/blueprints/eval_context.rb', line 26 def build(*blueprints) Namespace.root.build(blueprints) end |
#copy_instance_variables(target) ⇒ Object
Copy instance variables to another object.
5 6 7 8 9 |
# File 'lib/blueprints/eval_context.rb', line 5 def copy_instance_variables(target) instance_variables.each do |iv_name| target.instance_variable_set(iv_name, instance_variable_get(iv_name)) end end |
#instance_eval(context, options, &block) ⇒ Object
Sets options and attributes and evaluates block against self.
14 15 16 17 18 19 20 21 |
# File 'lib/blueprints/eval_context.rb', line 14 def instance_eval(context, , &block) = normalize_hash() define_singleton_method(:options) { } attributes = normalize_hash(context.attributes).merge() define_singleton_method(:attributes) { attributes } super(&block) end |
#normalize_hash(hash) ⇒ Hash
Normalizes attributes hash by evaluating all Proc and Blueprints::Dependency objects against itself.
33 34 35 36 37 38 39 40 41 |
# File 'lib/blueprints/eval_context.rb', line 33 def normalize_hash(hash) hash.each_with_object({}) do |(attr, value), normalized| normalized[attr] = if value.respond_to?(:to_proc) and not Symbol === value instance_exec(&value) else value end end end |