Module: ActiveGroonga::Persistence
- Included in:
- Base
- Defined in:
- lib/active_groonga/persistence.rb
Instance Method Summary collapse
- #becomes(klass) ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
- #update_attribute(name, value) ⇒ Object
- #update_attributes(attributes) ⇒ Object
- #update_attributes!(attributes) ⇒ Object
Instance Method Details
#becomes(klass) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/active_groonga/persistence.rb', line 50 def becomes(klass) became = klass.new became.instance_variable_set("@attributes", @attributes) became.instance_variable_set("@attributes_cache", @attributes_cache) became.instance_variable_set("@new_record", new_record?) became.instance_variable_set("@destroyed", destroyed?) became end |
#delete ⇒ Object
38 39 40 41 42 |
# File 'lib/active_groonga/persistence.rb', line 38 def delete table.delete(record_id) if persisted? @destroyed = true freeze end |
#destroy ⇒ Object
44 45 46 47 48 |
# File 'lib/active_groonga/persistence.rb', line 44 def destroy table.delete(record_id) if persisted? @destroyed = true freeze end |
#destroyed? ⇒ Boolean
22 23 24 |
# File 'lib/active_groonga/persistence.rb', line 22 def destroyed? @destroyed end |
#new_record? ⇒ Boolean
18 19 20 |
# File 'lib/active_groonga/persistence.rb', line 18 def new_record? @new_record end |
#persisted? ⇒ Boolean
26 27 28 |
# File 'lib/active_groonga/persistence.rb', line 26 def persisted? !new_record? and !destroyed? end |
#reload ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/active_groonga/persistence.rb', line 75 def reload if new_record? record = nil else record = table[record_id] end reload_attributes(record) @attributes_cache = {} self end |
#save(options = {}) ⇒ Object
30 31 32 |
# File 'lib/active_groonga/persistence.rb', line 30 def save(={}) create_or_update end |
#save!(options = {}) ⇒ Object
34 35 36 |
# File 'lib/active_groonga/persistence.rb', line 34 def save!(={}) create_or_update or raise(RecordNotSaved) end |
#update_attribute(name, value) ⇒ Object
59 60 61 62 63 |
# File 'lib/active_groonga/persistence.rb', line 59 def update_attribute(name, value) name = name.to_s send("#{name}=", value) save(:validate => false) end |
#update_attributes(attributes) ⇒ Object
65 66 67 68 |
# File 'lib/active_groonga/persistence.rb', line 65 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
70 71 72 73 |
# File 'lib/active_groonga/persistence.rb', line 70 def update_attributes!(attributes) self.attributes = attributes save! end |