lib/blueprints/helper.rb in blueprints-0.9.0 vs lib/blueprints/helper.rb in blueprints-1.0.0

- old
+ new

@@ -10,29 +10,37 @@ # @example passing options to several blueprints. # build :pear, :apple => {:color => 'red'}, :orange => {:color => 'orange'} # @param [Array<Symbol, String, Hash>] names Names of blueprints/namespaces to build. Pass Hash if you want to pass additional options. # @return Return value of last blueprint def build(*names) - Namespace.root.build(names, self, true) + Namespace.root.build(names, self) end - # Same as #build except that you can use it to build same blueprint several times. + # Same as Blueprints::Helper#build except that you can use it to build same blueprint several times. # @overload build!(*names) - # @param [Array<Symbol, String, Hash>] names Names of blueprints/namespaces to build. Pass Hash if you want to pass additional options. - # @return Return value of last blueprint + # @param names (see Helper#build) + # @return (see Helper#build) # @overload build!(count, *names) # @param [Integer] count Times to build passed blueprint - # @param [Array<Symbol, String, Hash>] names Names of blueprints/namespaces to build. Pass Hash if you want to pass additional options. + # @param names (see Helper#build) # @return [Array] Array of return values of last blueprint, which is same size as count that you pass def build!(*names) if names.first.is_a?(Integer) (0...names.shift).collect { build! *names } else - Namespace.root.build(names, self, false) + Namespace.root.build(names, self, :rebuild => true) end end + # Same as Blueprints::Helper#build except it also allows you to pass strategy to use (#build always uses default strategy). + # @param [Symbol] strategy Strategy to use when building blueprint/namespace. + # @param names (see Helper#build) + # @return (see Helper#build) + def build_with(strategy, *names) + Namespace.root.build(names, self, :strategy => strategy) + end + # Returns attributes that are used to build blueprint. # @example Setting and retrieving attributes. # # In blueprint.rb file # attributes(:name => 'apple').blueprint :apple do # Fruit.build attributes @@ -42,12 +50,12 @@ # build_attributes :apple #=> {:name => 'apple'} # @param [Symbol, String] name Name of blueprint/namespace. # @return [Hash] Normalized attributes of blueprint/namespace def build_attributes(name) blueprint = Namespace.root[name] - blueprint.build_parents(Namespace.root.eval_context) - Namespace.root.eval_context.normalize_hash(blueprint.attributes).tap { Namespace.root.eval_context.copy_instance_variables(self) } + blueprint.build_parents(self) + blueprint.normalized_attributes(self) end # Returns Blueprint::Dependency object that can be used to define dependencies on other blueprints. # @example Building :post blueprint with different user. # build :post => {:user => d(:admin)} @@ -62,10 +70,10 @@ # Demolishes built blueprints (by default simply calls destroy method on result of blueprint, but can be customized). # @example Demolish :apple and :pear blueprints # demolish :apple, :pear # @param [Array<Symbol, String>] names Names of blueprints/namespaces to demolish. def demolish(*names) - names.each { |name| Namespace.root[name].demolish(Namespace.root.eval_context) } + names.each { |name| Namespace.root[name].demolish(self) } end alias :build_blueprint :build alias :build_blueprint! :build! alias :blueprint_dependency :d