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.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#proc_class ⇒ Object
Returns the value of attribute proc_class.
-
#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.
- #klass ⇒ Object
- #run(context:) ⇒ Object
Constructor Details
#initialize(name, options = {}) ⇒ Definition
Returns a new instance of Definition.
10 11 12 13 14 15 16 17 |
# File 'lib/fixture_factory/definition.rb', line 10 def initialize(name, = {}) self.parent = .fetch(:parent) { default_parent_for(name) } self.proc_class = .fetch(:class) { parent.proc_class } 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
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/fixture_factory/definition.rb', line 19 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.
8 9 10 |
# File 'lib/fixture_factory/definition.rb', line 8 def fixture_method @fixture_method end |
#fixture_name ⇒ Object
Returns the value of attribute fixture_name.
8 9 10 |
# File 'lib/fixture_factory/definition.rb', line 8 def fixture_name @fixture_name end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'lib/fixture_factory/definition.rb', line 8 def parent @parent end |
#proc_class ⇒ Object
Returns the value of attribute proc_class.
8 9 10 |
# File 'lib/fixture_factory/definition.rb', line 8 def proc_class @proc_class end |
#sequence ⇒ Object
Returns the value of attribute sequence.
8 9 10 |
# File 'lib/fixture_factory/definition.rb', line 8 def sequence @sequence end |
Instance Method Details
#fixture_args ⇒ Object
37 38 39 |
# File 'lib/fixture_factory/definition.rb', line 37 def fixture_args [fixture_method, fixture_name] end |
#from_fixture? ⇒ Boolean
41 42 43 |
# File 'lib/fixture_factory/definition.rb', line 41 def from_fixture? fixture_name.present? && fixture_method.present? end |
#klass ⇒ Object
31 32 33 34 35 |
# File 'lib/fixture_factory/definition.rb', line 31 def klass @klass ||= proc_class.call rescue NameError raise WrongClassError, proc_class end |
#run(context:) ⇒ Object
45 46 47 |
# File 'lib/fixture_factory/definition.rb', line 45 def run(context:) FixtureFactory.evaluate(runner, context: context) end |