Class: FixtureFactory::Definition
- Inherits:
-
Object
- Object
- FixtureFactory::Definition
- Defined in:
- lib/fixture_factory/definition.rb
Overview
:nodoc:
Constant Summary collapse
- EMPTY_BLOCK =
proc {}
Instance Attribute Summary collapse
- #block ⇒ Object
-
#fixture_method ⇒ Object
Returns the value of attribute fixture_method.
-
#fixture_name ⇒ Object
Returns the value of attribute fixture_name.
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
Instance Method Summary collapse
- #fixture_args ⇒ Object
- #from_fixture? ⇒ Boolean
-
#initialize(name, options = {}) ⇒ Definition
constructor
A new instance of Definition.
- #run(context:) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Definition
11 12 13 14 15 16 17 18 |
# File 'lib/fixture_factory/definition.rb', line 11 def initialize(name, = {}) self.parent = .fetch(:parent) { default_parent_for(name) } self.klass = .fetch(:class) { parent.klass } self.fixture_method = .fetch(:via) { parent.fixture_method } self.fixture_name = .fetch(:like) { parent.fixture_name } self.block = .fetch(:block) { EMPTY_BLOCK } self.sequence = Sequence.new end |
Instance Attribute Details
#block ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fixture_factory/definition.rb', line 20 def block all_blocks = [parent&.block, @block].compact -> (*args) do all_blocks.reduce({}) do |attributes, block| block_attributes = FixtureFactory.evaluate( block, args: args, context: self ) attributes.merge(block_attributes) end end end |
#fixture_method ⇒ Object
Returns the value of attribute fixture_method.
9 10 11 |
# File 'lib/fixture_factory/definition.rb', line 9 def fixture_method @fixture_method end |
#fixture_name ⇒ Object
Returns the value of attribute fixture_name.
9 10 11 |
# File 'lib/fixture_factory/definition.rb', line 9 def fixture_name @fixture_name end |
#klass ⇒ Object
Returns the value of attribute klass.
7 8 9 |
# File 'lib/fixture_factory/definition.rb', line 7 def klass @klass end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/fixture_factory/definition.rb', line 9 def parent @parent end |
#sequence ⇒ Object
Returns the value of attribute sequence.
9 10 11 |
# File 'lib/fixture_factory/definition.rb', line 9 def sequence @sequence end |
Instance Method Details
#fixture_args ⇒ Object
43 44 45 |
# File 'lib/fixture_factory/definition.rb', line 43 def fixture_args [fixture_method, fixture_name] end |
#from_fixture? ⇒ Boolean
47 48 49 |
# File 'lib/fixture_factory/definition.rb', line 47 def from_fixture? fixture_name.present? && fixture_method.present? end |
#run(context:) ⇒ Object
51 52 53 |
# File 'lib/fixture_factory/definition.rb', line 51 def run(context:) FixtureFactory.evaluate(runner, context: context) end |