Module: OData::Model::Persistence
- Extended by:
- ActiveSupport::Concern
- Included in:
- OData::Model
- Defined in:
- lib/odata/model/persistence.rb
Overview
The OData::Model::Persistence module encapsulates all the functionality specifically needed for OData::Model to persist data to and from the OData gem.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#initialize(attr_values = {}) ⇒ Object
A simple initializer that just accepts a hash and sets any matching accessors with the supplied value.
-
#persisted? ⇒ Boolean
Returns whether the current instance has been persisted.
-
#reload! ⇒ Object
Reload the model from OData.
-
#save ⇒ Object
Save the current model.
Instance Method Details
#initialize(attr_values = {}) ⇒ Object
A simple initializer that just accepts a hash and sets any matching accessors with the supplied value
15 16 17 18 19 20 21 22 23 |
# File 'lib/odata/model/persistence.rb', line 15 def initialize(attr_values = {}) attr_values.each do |attr_name, value| begin send("#{attr_name.to_sym}=", value) rescue NoMethodError next end end end |
#persisted? ⇒ Boolean
Returns whether the current instance has been persisted.
27 28 29 30 31 32 33 34 |
# File 'lib/odata/model/persistence.rb', line 27 def persisted? if instance_variable_defined?(:@persisted) instance_variable_get(:@persisted) else instance_variable_set(:@persisted, false) instance_variable_get(:@persisted) end end |
#reload! ⇒ Object
Reload the model from OData
44 45 46 47 |
# File 'lib/odata/model/persistence.rb', line 44 def reload! # TODO reload OData entity #reset_changes end |
#save ⇒ Object
Save the current model.
37 38 39 40 41 |
# File 'lib/odata/model/persistence.rb', line 37 def save self.class.odata_service[odata_entity_set_name] << odata_entity instance_variable_set(:@persisted, true) unless odata_entity.any_errors? #changes_applied end |