Class: AutoBuild::HasManyHook
- Inherits:
-
Object
- Object
- AutoBuild::HasManyHook
- Defined in:
- lib/auto_build/has_many_hook.rb
Instance Attribute Summary collapse
-
#association_name ⇒ Object
readonly
Returns the value of attribute association_name.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #attach ⇒ Object
- #code ⇒ Object
-
#initialize(model, name, options) ⇒ HasManyHook
constructor
A new instance of HasManyHook.
Constructor Details
#initialize(model, name, options) ⇒ HasManyHook
Returns a new instance of HasManyHook.
5 6 7 8 9 |
# File 'lib/auto_build/has_many_hook.rb', line 5 def initialize(model, name, ) @model = model @association_name = name @options = end |
Instance Attribute Details
#association_name ⇒ Object (readonly)
Returns the value of attribute association_name.
3 4 5 |
# File 'lib/auto_build/has_many_hook.rb', line 3 def association_name @association_name end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/auto_build/has_many_hook.rb', line 3 def model @model end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/auto_build/has_many_hook.rb', line 3 def @options end |
Instance Method Details
#attach ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/auto_build/has_many_hook.rb', line 11 def attach hook_code = code name = association_name = model.class_eval do after_initialize do |record| count = number_of_records_to_create(name, ) record.instance_eval(hook_code * count) end end end |
#code ⇒ Object
24 25 26 |
# File 'lib/auto_build/has_many_hook.rb', line 24 def code "self.#{association_name}.build;" end |