module SsredisOrm::Model::InstanceMethods
Attributes
id[RW]
Public Instance Methods
delete()
click to toggle source
# File lib/ssredis_orm/model.rb, line 56 def delete $redis.del "#{self.class.name}:#{@id}" if @id @id = nil end
fields()
click to toggle source
# File lib/ssredis_orm/model.rb, line 47 def fields self.class.fields end
save()
click to toggle source
# File lib/ssredis_orm/model.rb, line 51 def save @id ||= $redis.incr "#{self.class.name}:autoincrement" $redis.set "#{self.class.name}:#{@id}", self.to_json end
to_json()
click to toggle source
# File lib/ssredis_orm/model.rb, line 61 def to_json hash = Hash.new { |hash, key| hash[key] = self.send(key).to_json unless self.send(key).nil? } self.fields.each do |field| hash[field] end return hash.to_json end