Class: ActiveForce::Query
- Inherits:
-
Object
- Object
- ActiveForce::Query
- Defined in:
- lib/active_force/query.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Instance Method Summary collapse
- #all ⇒ Object
- #count ⇒ Object
- #fields(fields_collection = []) ⇒ Object
- #find(id) ⇒ Object
- #first ⇒ Object
-
#initialize(table) ⇒ Query
constructor
A new instance of Query.
- #join(object_query) ⇒ Object
- #last ⇒ Object
- #limit(size) ⇒ Object
- #limit_value ⇒ Object
- #offset(offset) ⇒ Object
- #offset_value ⇒ Object
- #order(order) ⇒ Object
- #select(*columns) ⇒ Object
- #to_s ⇒ Object
- #where(condition) ⇒ Object
Constructor Details
#initialize(table) ⇒ Query
Returns a new instance of Query.
5 6 7 8 9 10 |
# File 'lib/active_force/query.rb', line 5 def initialize table @table = table @conditions = [] @table_id = 'Id' @query_fields = [@table_id] end |
Instance Attribute Details
#table ⇒ Object (readonly)
Returns the value of attribute table.
3 4 5 |
# File 'lib/active_force/query.rb', line 3 def table @table end |
Instance Method Details
#all ⇒ Object
16 17 18 |
# File 'lib/active_force/query.rb', line 16 def all self end |
#count ⇒ Object
84 85 86 87 |
# File 'lib/active_force/query.rb', line 84 def count @query_fields = ["count(Id)"] self end |
#fields(fields_collection = []) ⇒ Object
12 13 14 |
# File 'lib/active_force/query.rb', line 12 def fields fields_collection = [] @query_fields += fields_collection.to_a end |
#find(id) ⇒ Object
66 67 68 69 |
# File 'lib/active_force/query.rb', line 66 def find id where "#{ @table_id } = '#{ id }'" limit 1 end |
#first ⇒ Object
71 72 73 |
# File 'lib/active_force/query.rb', line 71 def first limit 1 end |
#join(object_query) ⇒ Object
79 80 81 82 |
# File 'lib/active_force/query.rb', line 79 def join object_query fields ["(#{ object_query.to_s })"] self end |
#last ⇒ Object
75 76 77 |
# File 'lib/active_force/query.rb', line 75 def last order("Id DESC").limit(1) end |
#limit(size) ⇒ Object
48 49 50 51 |
# File 'lib/active_force/query.rb', line 48 def limit size @size = size if size self end |
#limit_value ⇒ Object
53 54 55 |
# File 'lib/active_force/query.rb', line 53 def limit_value @size end |
#offset(offset) ⇒ Object
57 58 59 60 |
# File 'lib/active_force/query.rb', line 57 def offset offset @offset = offset self end |
#offset_value ⇒ Object
62 63 64 |
# File 'lib/active_force/query.rb', line 62 def offset_value @offset end |
#order(order) ⇒ Object
43 44 45 46 |
# File 'lib/active_force/query.rb', line 43 def order order @order = order if order self end |
#select(*columns) ⇒ Object
33 34 35 36 |
# File 'lib/active_force/query.rb', line 33 def select *columns @query_fields = columns self end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/active_force/query.rb', line 20 def to_s <<-SOQL.gsub(/\s+/, " ").strip SELECT #{ build_select } FROM #{ @table } #{ build_where } #{ build_order } #{ build_limit } #{ build_offset } SOQL end |
#where(condition) ⇒ Object
38 39 40 41 |
# File 'lib/active_force/query.rb', line 38 def where condition @conditions << condition if condition self end |