Module: QuickbaseRecord::Queries::ClassMethods
- Defined in:
- lib/quickbase_record/queries.rb
Instance Method Summary collapse
- #build_query(query_hash) ⇒ Object
- #clist ⇒ Object
- #create(attributes = {}) ⇒ Object
- #dbid ⇒ Object
- #find(id) ⇒ Object
- #query(query_string) ⇒ Object
- #where(query_hash) ⇒ Object
Instance Method Details
#build_query(query_hash) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/quickbase_record/queries.rb', line 58 def build_query(query_hash) return convert_query_string(query_hash) if query_hash.is_a? String query_hash.map do |field_name, values| fid = convert_field_name_to_fid(field_name) if values.is_a? Array join_with_or(fid, values) elsif values.is_a? Hash join_with_custom(fid, values) else join_with_and(fid, values) end end.join("AND") end |
#clist ⇒ Object
15 16 17 |
# File 'lib/quickbase_record/queries.rb', line 15 def clist @clist ||= fields.reject{ |field_name| field_name == :dbid }.values.join('.') end |
#create(attributes = {}) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/quickbase_record/queries.rb', line 39 def create(attributes={}) raise StandardErrror, "You cannot call #{self}.create() with an :id attribute" if attributes.include?(:id) object = new(attributes) object.save return object end |
#dbid ⇒ Object
11 12 13 |
# File 'lib/quickbase_record/queries.rb', line 11 def dbid @dbid ||= fields[:dbid] end |
#find(id) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/quickbase_record/queries.rb', line 19 def find(id) = { query: build_query(id: id), clist: clist } query_response = qb_client.do_query(dbid, ).first converted_response = convert_quickbase_response(query_response) new(converted_response) end |
#query(query_string) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/quickbase_record/queries.rb', line 46 def query(query_string) = { query: build_query(query_string), clist: clist } query_response = qb_client.do_query(dbid, ) array_of_new_objects = query_response.map do |response| converted_response = convert_quickbase_response(response) new(converted_response) end return array_of_new_objects end |
#where(query_hash) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/quickbase_record/queries.rb', line 27 def where(query_hash) = { query: build_query(query_hash), clist: clist } query_response = qb_client.do_query(dbid, ) array_of_new_objects = query_response.map do |response| converted_response = convert_quickbase_response(response) new(converted_response) end return array_of_new_objects end |