Module: MassiveRecord::ORM::Persistence
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/massive_record/orm/persistence.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#atomic_increment!(attr_name, by = 1) ⇒ Object
Atomic increment of an attribute.
- #decrement(attr_name, by = 1) ⇒ Object
- #decrement!(attr_name, by = 1) ⇒ Object
- #destroy ⇒ Object (also: #delete)
- #destroyed? ⇒ Boolean
- #increment(attr_name, by = 1) ⇒ Object
- #increment!(attr_name, by = 1) ⇒ Object
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
- #reload ⇒ Object
- #save ⇒ Object
- #save! ⇒ Object
-
#touch ⇒ Object
TODO This actually does nothing atm, but it’s here and callbacks on it is working.
- #update_attribute(attr_name, value) ⇒ Object
- #update_attributes(attributes) ⇒ Object
- #update_attributes!(attributes) ⇒ Object
Instance Method Details
#atomic_increment!(attr_name, by = 1) ⇒ Object
Atomic increment of an attribute. Please note that it’s the adapter (or the wrapper) which needs to guarantee that the update is atomic, and as of writing this the Thrift adapter / wrapper does not do this anatomic.
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/massive_record/orm/persistence.rb', line 126 def atomic_increment!(attr_name, by = 1) self.class.ensure_that_we_have_table_and_column_families! attr_name = attr_name.to_s ensure_proper_binary_integer_representation(attr_name) self[attr_name] = row_for_record.atomic_increment(attributes_schema[attr_name].unique_name, by) @new_record = false self[attr_name] end |
#decrement(attr_name, by = 1) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/massive_record/orm/persistence.rb', line 137 def decrement(attr_name, by = 1) raise NotNumericalFieldError unless attributes_schema[attr_name.to_s].type == :integer self[attr_name] ||= 0 self[attr_name] -= by self end |
#decrement!(attr_name, by = 1) ⇒ Object
144 145 146 |
# File 'lib/massive_record/orm/persistence.rb', line 144 def decrement!(attr_name, by = 1) decrement(attr_name, by).update_attribute(attr_name, self[attr_name]) end |
#destroy ⇒ Object Also known as: delete
103 104 105 |
# File 'lib/massive_record/orm/persistence.rb', line 103 def destroy @destroyed = (persisted? ? row_for_record.destroy : true) and freeze end |
#destroyed? ⇒ Boolean
64 65 66 |
# File 'lib/massive_record/orm/persistence.rb', line 64 def destroyed? @destroyed end |
#increment(attr_name, by = 1) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/massive_record/orm/persistence.rb', line 111 def increment(attr_name, by = 1) raise NotNumericalFieldError unless attributes_schema[attr_name.to_s].type == :integer self[attr_name] ||= 0 self[attr_name] += by self end |
#increment!(attr_name, by = 1) ⇒ Object
118 119 120 |
# File 'lib/massive_record/orm/persistence.rb', line 118 def increment!(attr_name, by = 1) increment(attr_name, by).update_attribute(attr_name, self[attr_name]) end |
#new_record? ⇒ Boolean
56 57 58 |
# File 'lib/massive_record/orm/persistence.rb', line 56 def new_record? @new_record end |
#persisted? ⇒ Boolean
60 61 62 |
# File 'lib/massive_record/orm/persistence.rb', line 60 def persisted? !(new_record? || destroyed?) end |
#reload ⇒ Object
69 70 71 72 |
# File 'lib/massive_record/orm/persistence.rb', line 69 def reload self.attributes_raw = self.class.find(id).attributes if persisted? self end |
#save ⇒ Object
74 75 76 |
# File 'lib/massive_record/orm/persistence.rb', line 74 def save(*) create_or_update end |
#save! ⇒ Object
78 79 80 |
# File 'lib/massive_record/orm/persistence.rb', line 78 def save!(*) create_or_update or raise RecordNotSaved end |
#touch ⇒ Object
TODO This actually does nothing atm, but it’s here and callbacks on it
is working.
99 100 101 |
# File 'lib/massive_record/orm/persistence.rb', line 99 def touch true end |
#update_attribute(attr_name, value) ⇒ Object
82 83 84 85 |
# File 'lib/massive_record/orm/persistence.rb', line 82 def update_attribute(attr_name, value) self[attr_name] = value save(:validate => false) end |
#update_attributes(attributes) ⇒ Object
87 88 89 90 |
# File 'lib/massive_record/orm/persistence.rb', line 87 def update_attributes(attributes) self.attributes = attributes save end |
#update_attributes!(attributes) ⇒ Object
92 93 94 95 |
# File 'lib/massive_record/orm/persistence.rb', line 92 def update_attributes!(attributes) self.attributes = attributes save! end |