Module: TcAdapter::ClassMethods
- Defined in:
- lib/models/tc_adapter.rb
Instance Method Summary collapse
-
#all ⇒ Object
TODO add pagination.
- #delete(pk) ⇒ Object
- #get(hash) ⇒ Object
- #set(attributes) ⇒ Object
- #set!(attributes) ⇒ Object
Instance Method Details
#all ⇒ Object
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
72 73 74 75 |
# File 'lib/models/tc_adapter.rb', line 72 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 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/models/tc_adapter.rb', line 21 def get(hash) if hash[:id] pk = hash[:id] if pk.length > 0 result = TcUser.get(pk) else nil end else result = TcUser.query do |q| hash.each do |key, value| q.add key.to_s, :streq, value.to_s end end[0] end #elsif 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 #end if result self.new result else nil end end |
#set(attributes) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/models/tc_adapter.rb', line 50 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 if attributes['email'].length == 0 error = 'You need to provide an email address' else error = 'That email is already taken' end TcUser.new(attributes, error) end end |