lib/blueprints/root_namespace.rb in blueprints-0.4.2 vs lib/blueprints/root_namespace.rb in blueprints-0.5.0

- old
+ new

@@ -7,10 +7,11 @@ attr_accessor :executed_plans def initialize @executed_plans = Set.new @global_executed_plans = Set.new + @auto_iv_list = Set.new super '' end # Loads all instance variables from global context to current one. @@ -36,17 +37,26 @@ @global_variables = YAML.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) - options = names.extract_options! - names.map {|name| self[name].build(options) } + names.inject(nil) do |result, member| + if member.is_a?(Hash) + member.map {|name, options| self[name].build(options) }.last + else + self[member].build + end + end end - # Sets instance variable in current context to passed value. + # 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) name = "@#{name}" unless name.to_s[0, 1] == "@" - @context.instance_variable_set(name, value) unless @context.instance_variable_get(name) + if !@context.instance_variable_get(name) or @auto_iv_list.include?(name) + @auto_iv_list << name + @context.instance_variable_set(name, value) + end end @@root = RootNamespace.new end end