module Tarantool::BaseRecord::InstanceMethods
Attributes
__new_record[RW]
attributes[R]
new_record[RW]
new_record?[RW]
Public Instance Methods
==(other)
click to toggle source
# File lib/tarantool/base_record.rb, line 346 def ==(other) equal?(other) || (other.class == self.class && id == other.id) end
_raise_doesnt_exists(action = "update")
click to toggle source
# File lib/tarantool/base_record.rb, line 368 def _raise_doesnt_exists(action = "update") raise TupleDoesntExists.new(0x3102, "Record which you wish to #{action}, doesn't exists") end
_tail()
click to toggle source
# File lib/tarantool/base_record.rb, line 309 def _tail @attributes[:_tail] end
_tail=(v)
click to toggle source
# File lib/tarantool/base_record.rb, line 313 def _tail=(v) @attributes[:_tail] = v end
auto_space()
click to toggle source
# File lib/tarantool/base_record.rb, line 332 def auto_space self.class.space end
id()
click to toggle source
# File lib/tarantool/base_record.rb, line 322 def id (primary = self.class.primary_index).size == 1 ? @attributes[primary[0]] : @attributes.values_at(*primary) end
increment(field, by = 1)
click to toggle source
# File lib/tarantool/base_record.rb, line 364 def increment(field, by = 1) update([[field.to_sym, :+, by]]) end
new_record!()
click to toggle source
# File lib/tarantool/base_record.rb, line 293 def new_record! @__new_record = true self end
old_record!()
click to toggle source
# File lib/tarantool/base_record.rb, line 298 def old_record! @__new_record = false self end
reload()
click to toggle source
# File lib/tarantool/base_record.rb, line 336 def reload if hash = space.by_pk(id) @__new_record = false @attributes = hash self else _raise_doesnt_exists("reload") end end
set_attributes(attributes)
click to toggle source
# File lib/tarantool/base_record.rb, line 303 def set_attributes(attributes) attributes.each do |k, v| send("#{k}=", v) end end
space()
click to toggle source
# File lib/tarantool/base_record.rb, line 328 def space self.class.space end
update(ops)
click to toggle source
update record in db first, reload it then
record.update({:state => 'sleep', :sleep_count => [:+, 1]}) record.update([[:state, 'sleep'], [:sleep_count, :+, 1]])
# File lib/tarantool/base_record.rb, line 354 def update(ops) raise UpdateNewRecord, "Could not call update on new record" if @__new_record unless new_attrs = space.update(id, ops, return_tuple: true) _raise_doesnt_exists end @attributes = new_attrs self end
update_attributes(attributes)
click to toggle source
# File lib/tarantool/base_record.rb, line 317 def update_attributes(attributes) set_attributes(attributes) save end