Module: Og::EntityMixin
Overview
Include this module to classes to make them managable by Og. – gmosx, WARTNING: If you change the methods here, don’t forget to update the Cacheable overrides. ++
Class Method Summary collapse
Instance Method Summary collapse
- #assign_properties(values, options = {}) ⇒ Object (also: #assign)
-
#delete(cascade = true) ⇒ Object
(also: #delete!)
Delete this entity instance from the store.
-
#force_save!(options = nil) ⇒ Object
Force saving of the objects, even if the validations don’t pass.
-
#insert ⇒ Object
Insert the object in the store.
- #og_clone(*args) ⇒ Object
- #og_quote(obj) ⇒ Object
-
#properties_to_hash ⇒ Object
Returns a symbol => value hash of the object’s properties.
-
#reload ⇒ Object
(also: #reload!)
Reload this entity instance from the store.
-
#save(options = nil) ⇒ Object
(also: #save!, #validate_and_save)
Persist the object.
-
#saved? ⇒ Boolean
(also: #serialized?)
Is this object saved in the store?.
- #transaction(&block) ⇒ Object
-
#update(options = nil) ⇒ Object
Update an existing object in the store.
- #update_by_sql(set) ⇒ Object (also: #update_sql, #supdate)
- #update_properties(*properties) ⇒ Object (also: #update_property, #pupdate)
Class Method Details
.included(base) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/og/entity.rb', line 19 def self.included(base) # If the after_enchant callback is defined, call it # to allow for some customization. Have a look at cacheable # for an example. if base.respond_to?(:after_enchant) base.after_enchant(base) end end |
Instance Method Details
#assign_properties(values, options = {}) ⇒ Object Also known as: assign
94 95 96 97 |
# File 'lib/og/entity.rb', line 94 def assign_properties(values, = {}) Property.populate_object(self, values, ) return self end |
#delete(cascade = true) ⇒ Object Also known as: delete!
Delete this entity instance from the store.
78 79 80 |
# File 'lib/og/entity.rb', line 78 def delete(cascade = true) self.class.ogmanager.store.delete(self, self.class, cascade) end |
#force_save!(options = nil) ⇒ Object
Force saving of the objects, even if the validations don’t pass.
40 41 42 |
# File 'lib/og/entity.rb', line 40 def force_save!( = nil) self.class.ogmanager.store.force_save(self, ) end |
#insert ⇒ Object
Insert the object in the store.
46 47 48 49 |
# File 'lib/og/entity.rb', line 46 def insert self.class.ogmanager.store.insert(self) return self end |
#og_clone(*args) ⇒ Object
114 115 116 |
# File 'lib/og/entity.rb', line 114 def og_clone(*args) Og::Entity.clone(self,*args) end |
#og_quote(obj) ⇒ Object
110 111 112 |
# File 'lib/og/entity.rb', line 110 def og_quote(obj) self.class.ogmanager.store.quote(obj) end |
#properties_to_hash ⇒ Object
Returns a symbol => value hash of the object’s properties.
103 104 105 106 107 108 |
# File 'lib/og/entity.rb', line 103 def properties_to_hash hash = {} for sym, prop in self.class.properties hash[sym] = instance_variable_get("@#{sym}") end end |
#reload ⇒ Object Also known as: reload!
Reload this entity instance from the store.
71 72 73 |
# File 'lib/og/entity.rb', line 71 def reload self.class.ogmanager.store.reload(self, self.pk) end |
#save(options = nil) ⇒ Object Also known as: save!, validate_and_save
Persist the object.
31 32 33 |
# File 'lib/og/entity.rb', line 31 def save( = nil) self.class.ogmanager.store.save(self, ) end |
#saved? ⇒ Boolean Also known as: serialized?
Is this object saved in the store?
89 90 91 |
# File 'lib/og/entity.rb', line 89 def saved? not @oid.nil? end |
#transaction(&block) ⇒ Object
83 84 85 |
# File 'lib/og/entity.rb', line 83 def transaction(&block) self.class.ogmanager.store.transaction(&block) end |
#update(options = nil) ⇒ Object
Update an existing object in the store.
53 54 55 |
# File 'lib/og/entity.rb', line 53 def update( = nil) self.class.ogmanager.store.update(self, ) end |
#update_by_sql(set) ⇒ Object Also known as: update_sql, supdate
63 64 65 |
# File 'lib/og/entity.rb', line 63 def update_by_sql(set) self.class.ogmanager.store.update_by_sql(self, set) end |
#update_properties(*properties) ⇒ Object Also known as: update_property, pupdate
57 58 59 |
# File 'lib/og/entity.rb', line 57 def update_properties(*properties) self.class.ogmanager.store.update(self, :only => properties) end |