Module: TcAdapter::ClassMethods

Defined in:
lib/models/tc_adapter.rb

Instance Method Summary collapse

Instance Method Details

#allObject

TODO add pagination



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

def all
  result = TcUser.query do |q|
    q.order_by 'created_at_i', :numdesc
  end

  #these will be the same for all adapters, they should be defined in the user class, and these methods should have a different name?
  result.collect {|instance| self.new instance }
end

#delete(pk) ⇒ Object



52
53
54
55
# File 'lib/models/tc_adapter.rb', line 52

def delete(pk)
  #true or false
  !!TcUser.delete(pk)
end

#get(hash) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/models/tc_adapter.rb', line 21

def get(hash)
  #because with TcUser email and id are the same because the email is the id
  if hash[:email]
    result = TcUser.query do |q|
      q.add 'email', :streq, hash[:email]
    end[0]
    #the zero is because this returns an array but get should return the first result
  elsif hash[:id]
    pk = hash[:id]
    result = TcUser.get(pk)
  end

  if result
    self.new result
  else
    nil
  end
end

#set(attributes) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/models/tc_adapter.rb', line 40

def set(attributes)
  user = TcUser.query do |q|
    q.add 'email', :streq, attributes['email']
  end

  if user == [] #no user
    self.new TcUser.set(attributes)
  else
    false
  end
end