Class: Fixjour::Generator
Overview
This generates a new instance of a model object for the new_ method.
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #args(overrides) ⇒ Object
- #call(context, overrides = {}) ⇒ Object
-
#initialize(klass, block) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(klass, block) ⇒ Generator
Returns a new instance of Generator.
7 8 9 |
# File 'lib/fixjour/generator.rb', line 7 def initialize(klass, block) @klass, @block = klass, block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
5 6 7 |
# File 'lib/fixjour/generator.rb', line 5 def block @block end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/fixjour/generator.rb', line 5 def klass @klass end |
Instance Method Details
#args(overrides) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/fixjour/generator.rb', line 20 def args(overrides) case block.arity when 1 then [MergingProxy.new(klass, overrides)] when 2 then [MergingProxy.new(klass, overrides), overrides] end end |
#call(context, overrides = {}) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/fixjour/generator.rb', line 11 def call(context, overrides={}) overrides = OverridesHash.new(overrides) result = block.bind(context).call(*args(overrides)) case result when Hash then klass.new(result.merge(overrides)) else result end end |