Module: ActiveGroonga::Persistence
- Included in:
- Base
- Defined in:
- lib/active_groonga/persistence.rb
Instance Method Summary (collapse)
- - (Object) becomes(klass)
- - (Object) delete
- - (Object) destroy
- - (Boolean) destroyed?
- - (Boolean) new_record?
- - (Boolean) persisted?
- - (Object) reload
- - (Object) save(options = {})
- - (Object) save!(options = {})
- - (Object) update_attribute(name, value)
- - (Object) update_attributes(attributes)
- - (Object) update_attributes!(attributes)
Instance Method Details
- (Object) becomes(klass)
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 |
- (Object) delete
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 |
- (Object) destroy
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 |
- (Boolean) destroyed?
22 23 24 |
# File 'lib/active_groonga/persistence.rb', line 22 def destroyed? @destroyed end |
- (Boolean) new_record?
18 19 20 |
# File 'lib/active_groonga/persistence.rb', line 18 def new_record? @new_record end |
- (Boolean) persisted?
26 27 28 |
# File 'lib/active_groonga/persistence.rb', line 26 def persisted? !new_record? and !destroyed? end |
- (Object) reload
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 |
- (Object) save(options = {})
30 31 32 |
# File 'lib/active_groonga/persistence.rb', line 30 def save(={}) create_or_update end |
- (Object) save!(options = {})
34 35 36 |
# File 'lib/active_groonga/persistence.rb', line 34 def save!(={}) create_or_update or raise(RecordNotSaved) end |
- (Object) update_attribute(name, value)
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 |
- (Object) update_attributes(attributes)
65 66 67 68 |
# File 'lib/active_groonga/persistence.rb', line 65 def update_attributes(attributes) self.attributes = attributes save end |
- (Object) update_attributes!(attributes)
70 71 72 73 |
# File 'lib/active_groonga/persistence.rb', line 70 def update_attributes!(attributes) self.attributes = attributes save! end |