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
62 63 64 65 |
# File 'lib/models/tc_adapter.rb', line 62 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 |
# File 'lib/models/tc_adapter.rb', line 21 def get(hash) if hash[:id] pk = hash[:id] result = TcUser.get(pk) 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 |