Module: SsredisOrm::Model

Defined in:
lib/ssredis_orm/model.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



4
5
6
7
8
# File 'lib/ssredis_orm/model.rb', line 4

def self.extended(base)
  base.class_eval do
    include InstanceMethods
  end
end

Instance Method Details

#create(options = {}) ⇒ Object



21
22
23
24
25
26
27
# 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) ⇒ Object



10
11
12
13
14
15
# File 'lib/ssredis_orm/model.rb', line 10

def field(*args)
  args.each do |arg|
    attr_accessor arg
    fields << arg
  end
end

#fieldsObject



17
18
19
# File 'lib/ssredis_orm/model.rb', line 17

def fields
  @fields ||= []
end

#find(id) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# 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