module SsredisOrm::Model
Public Class Methods
extended(base)
click to toggle source
# File lib/ssredis_orm/model.rb, line 4 def self.extended(base) base.class_eval do include InstanceMethods end end
Public Instance Methods
create(options={})
click to toggle source
# File lib/ssredis_orm/model.rb, line 21 def create(options={}) temp = self.new options.each_pair do |key, value| temp.send("#{key.to_s}=",value) if temp.respond_to? "#{key}=" end return temp end
field(*args)
click to toggle source
# File lib/ssredis_orm/model.rb, line 10 def field(*args) args.each do |arg| attr_accessor arg fields << arg end end
fields()
click to toggle source
# File lib/ssredis_orm/model.rb, line 17 def fields @fields ||= [] end
find(id)
click to toggle source
# File lib/ssredis_orm/model.rb, line 29 def find(id) result = JSON.load($redis.get "#{self.name}:#{id}") return if result.nil? temp = self.new temp.id = id result.each_pair do |key, value| temp.send("#{key.to_s}=",JSON.load(value)) if temp.respond_to? "#{key}=" end return temp end