Module: Blueprints::Helper
- Included in:
- ActiveSupport::TestCase
- Defined in:
- lib/blueprints/helper.rb
Overview
A helper module that should be included in test framework. Adds methods build
and demolish
Instance Method Summary collapse
-
#build(*names) ⇒ Object
(also: #build_blueprint)
Builds one or more blueprints by their names.
-
#build!(*names) ⇒ Object
(also: #build_blueprint!)
Same as #build except that you can use it to build same blueprint several times.
-
#build_attributes(name) ⇒ Hash
Returns attributes that are used to build blueprint.
-
#d(*args) ⇒ Blueprints::Dependency
(also: #blueprint_dependency)
Returns Blueprint::Dependency object that can be used to define dependencies on other blueprints.
-
#demolish(*names) ⇒ Object
(also: #blueprint_demolish)
Demolishes built blueprints (by default simply calls destroy method on result of blueprint, but can be customized).
Instance Method Details
#build(*names) ⇒ Object Also known as: build_blueprint
Builds one or more blueprints by their names. You can pass names as symbols or strings. You can also pass additional options hash which will be available by calling options
in blueprint block. Returns result of last blueprint block.
14 15 16 |
# File 'lib/blueprints/helper.rb', line 14 def build(*names) Namespace.root.build(names, self, true) end |
#build!(*names) ⇒ Object #build!(count, *names) ⇒ Array Also known as: build_blueprint!
Same as #build except that you can use it to build same blueprint several times.
26 27 28 29 30 31 32 |
# File 'lib/blueprints/helper.rb', line 26 def build!(*names) if names.first.is_a?(Integer) (0...names.shift).collect { build! *names } else Namespace.root.build(names, self, false) end end |
#build_attributes(name) ⇒ Hash
Returns attributes that are used to build blueprint.
45 46 47 48 49 |
# File 'lib/blueprints/helper.rb', line 45 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) } end |
#d(*args) ⇒ Blueprints::Dependency Also known as: blueprint_dependency
Returns Blueprint::Dependency object that can be used to define dependencies on other blueprints.
58 59 60 |
# File 'lib/blueprints/helper.rb', line 58 def d(*args) Dependency.new(*args) end |
#demolish(*names) ⇒ Object Also known as: blueprint_demolish
Demolishes built blueprints (by default simply calls destroy method on result of blueprint, but can be customized).
66 67 68 |
# File 'lib/blueprints/helper.rb', line 66 def demolish(*names) names.each { |name| Namespace.root[name].demolish(Namespace.root.eval_context) } end |