lib/blueprints/root_namespace.rb in blueprints-0.5.1 vs lib/blueprints/root_namespace.rb in blueprints-0.6.0
- old
+ new
@@ -15,11 +15,11 @@
end
# Loads all instance variables from global context to current one.
def setup
@context = Blueprints::Context.new
- YAML.load(@global_variables).each { |name, value| @context.instance_variable_set(name, value) }
+ Marshal.load(@global_variables).each { |name, value| @context.instance_variable_set(name, value) }
@executed_plans = @global_executed_plans.clone
end
# Copies all instance variables from current context to another one.
def copy_ivars(to)
@@ -29,24 +29,28 @@
end
# Sets up global context and executes prebuilt blueprints against it.
def prebuild(plans)
@context = Blueprints::Context.new
- @global_scenarios = build(*plans) if plans
+ @global_scenarios = build(plans) if plans
@global_executed_plans = @executed_plans
- @global_variables = YAML.dump(@context.instance_variables.each_with_object({}) {|iv, hash| hash[iv] = @context.instance_variable_get(iv) })
+ @global_variables = Marshal.dump(@context.instance_variables.each_with_object({}) {|iv, hash| hash[iv] = @context.instance_variable_get(iv) })
end
- # Builds blueprints that are passed against current context.
- def build(*names)
- names.inject(nil) do |result, member|
+ # Builds blueprints that are passed against current context. Copies instance variables to context given if one is given.
+ def build(names, context = nil, build_once = true)
+ names = [names] unless names.is_a?(Array)
+ result = names.inject(nil) do |result, member|
if member.is_a?(Hash)
- member.map {|name, options| self[name].build(options) }.last
+ member.map {|name, options| self[name].build(build_once, options) }.last
else
- self[member].build
+ self[member].build(build_once)
end
end
+
+ copy_ivars(context) if context
+ result
end
# Sets instance variable in current context to passed value. If instance variable with same name already exists, it
# is set only if it was set using this same method
def add_variable(name, value)