Class: FactoryBot::Callback
- Inherits:
-
Object
- Object
- FactoryBot::Callback
- Defined in:
- lib/factory_bot/callback.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(name, block) ⇒ Callback
constructor
A new instance of Callback.
- #run(instance, evaluator) ⇒ Object
Constructor Details
#initialize(name, block) ⇒ Callback
Returns a new instance of Callback.
5 6 7 8 |
# File 'lib/factory_bot/callback.rb', line 5 def initialize(name, block) @name = name.to_sym @block = block end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/factory_bot/callback.rb', line 3 def name @name end |
Instance Method Details
#==(other) ⇒ Object
18 19 20 21 |
# File 'lib/factory_bot/callback.rb', line 18 def ==(other) name == other.name && block == other.block end |
#run(instance, evaluator) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/factory_bot/callback.rb', line 10 def run(instance, evaluator) case block.arity when 1, -1, -2 then syntax_runner.instance_exec(instance, &block) when 2 then syntax_runner.instance_exec(instance, evaluator, &block) else syntax_runner.instance_exec(&block) end end |