Module: MongoidAdapter::ClassMethods

Defined in:
lib/models/mongoid_adapter.rb

Instance Method Summary collapse

Instance Method Details

#allObject



8
9
10
11
# File 'lib/models/mongoid_adapter.rb', line 8

def all
  result = MongoidUser.criteria.order_by([[:created_at, :desc]])
  result.collect {|instance| self.new instance }
end

#delete(pk) ⇒ Object



36
37
38
39
40
41
# File 'lib/models/mongoid_adapter.rb', line 36

def delete(pk)
  user = MongoidUser.find(pk)
  #returns nil on success. Is this correct? Will it return something else on failure?
  user.destroy
  user.destroyed?
end

#get(hash) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/models/mongoid_adapter.rb', line 13

def get(hash)
  if user = MongoidUser.first(:conditions => hash)
    self.new user
  else
    nil
  end
end

#set(attributes) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/models/mongoid_adapter.rb', line 21

def set(attributes)
  #puts attributes.inspect
  user = MongoidUser.new attributes
  #puts user.inspect
  #puts user.to_json
  user.save
  self.new user
end

#set!(attributes) ⇒ Object



30
31
32
33
34
# File 'lib/models/mongoid_adapter.rb', line 30

def set!(attributes)
  user = MongoidUser.new attributes
  user.save(:validate => false)
  self.new user
end