Module: ActiveRepository::Writers
- Included in:
- Base
- Defined in:
- lib/active_repository/writers.rb
Defined Under Namespace
Modules: InstanceMethods
Instance Method Summary collapse
-
#create(attributes = {}) ⇒ Object
Creates an object and persists it.
Instance Method Details
#create(attributes = {}) ⇒ Object
Creates an object and persists it.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/active_repository/writers.rb', line 5 def create(attributes={}) attributes = attributes.symbolize_keys if attributes.respond_to?(:symbolize_keys) object = self.new(attributes) if object.present? && object.valid? if persistence_class == self object.id = nil unless exists?(object.id) object.save else object = PersistenceAdapter.create(self, object.attributes) end end new_object = serialize!(object.reload.attributes) new_object.valid? new_object end |