Module: Create
- Included in:
- Fabrial
- Defined in:
- lib/fabrial/create.rb
Defined Under Namespace
Modules: AutoIds
Instance Attribute Summary collapse
-
#defaults ⇒ Object
Returns the value of attribute defaults.
Instance Method Summary collapse
Instance Attribute Details
#defaults ⇒ Object
Returns the value of attribute defaults.
4 5 6 |
# File 'lib/fabrial/create.rb', line 4 def defaults @defaults end |
Instance Method Details
#create(klass, data = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/fabrial/create.rb', line 6 def create(klass, data = {}) # Find the base class of any STI types base = klass.base_class default_data = defaults[klass] default_data ||= defaults[base] default_data ||= {} data = default_data.merge data klass.create! data end |