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?.
-
#to_rexml ⇒ Object
(also: #to_xml_dom)
convert Og object to REXML-Object example usage: User.to_rexml.
-
#to_xml ⇒ Object
convert Og object to an XML-String example usage: User.to_xml.
- #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
21 22 23 24 25 26 27 28 29 |
# File 'lib/og/entity.rb', line 21 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
96 97 98 99 |
# File 'lib/og/entity.rb', line 96 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.
80 81 82 |
# File 'lib/og/entity.rb', line 80 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.
42 43 44 |
# File 'lib/og/entity.rb', line 42 def force_save!( = nil) self.class.ogmanager.store.force_save!(self, ) end |
#insert ⇒ Object
Insert the object in the store.
48 49 50 51 |
# File 'lib/og/entity.rb', line 48 def insert self.class.ogmanager.store.insert(self) return self end |
#og_clone(*args) ⇒ Object
116 117 118 |
# File 'lib/og/entity.rb', line 116 def og_clone(*args) Og::Entity.clone(self,*args) end |
#og_quote(obj) ⇒ Object
112 113 114 |
# File 'lib/og/entity.rb', line 112 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.
105 106 107 108 109 110 |
# File 'lib/og/entity.rb', line 105 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.
73 74 75 |
# File 'lib/og/entity.rb', line 73 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.
33 34 35 |
# File 'lib/og/entity.rb', line 33 def save( = nil) self.class.ogmanager.store.save(self, ) end |
#saved? ⇒ Boolean Also known as: serialized?
Is this object saved in the store?
91 92 93 |
# File 'lib/og/entity.rb', line 91 def saved? not @oid.nil? end |
#to_rexml ⇒ Object Also known as: to_xml_dom
convert Og object to REXML-Object example usage: User.to_rexml
124 125 126 127 128 129 130 131 |
# File 'lib/og/entity.rb', line 124 def to_rexml xml = REXML::Element.new(self.class.to_s.downcase) xml.add_attribute("oid", self.oid.to_s) self.class.properties.keys.each do |key| xml << REXML::Element.new(key.to_s).add_text(self.send(key).to_s) unless key == :oid end return xml end |
#to_xml ⇒ Object
convert Og object to an XML-String example usage: User.to_xml
138 139 140 |
# File 'lib/og/entity.rb', line 138 def to_xml self.to_rexml.to_s end |
#transaction(&block) ⇒ Object
85 86 87 |
# File 'lib/og/entity.rb', line 85 def transaction(&block) self.class.ogmanager.store.transaction(&block) end |
#update(options = nil) ⇒ Object
Update an existing object in the store.
55 56 57 |
# File 'lib/og/entity.rb', line 55 def update( = nil) self.class.ogmanager.store.update(self, ) end |
#update_by_sql(set) ⇒ Object Also known as: update_sql, supdate
65 66 67 |
# File 'lib/og/entity.rb', line 65 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
59 60 61 |
# File 'lib/og/entity.rb', line 59 def update_properties(*properties) self.class.ogmanager.store.update(self, :only => properties) end |