Module: VTiger::Query

Defined in:
lib/v_tiger/query.rb

Instance Method Summary collapse

Instance Method Details

#build_query(objectType, options = {}) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/v_tiger/query.rb', line 3

def build_query(objectType, options = {})
  @objectType     = objectType
  @options        = options
  @query           = get('query', :query => query_string)
  @query['result'] += get_more while more_results_needed?
  @query
end

#get_moreObject



26
27
28
29
30
# File 'lib/v_tiger/query.rb', line 26

def get_more
  offset = @query['result'].count
  new_limit = @options[:limit] - offset
  get('query', :query => query_string(:limit => "#{offset}, #{new_limit}"))['result']
end

#more_results_needed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/v_tiger/query.rb', line 22

def more_results_needed?
  @options[:limit].present? && @query['result'].count < @options[:limit]
end

#query_string(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/v_tiger/query.rb', line 11

def query_string(options = {})
  limit = options[:limit] || @options[:limit]
  [].tap do |query|
    query << 'select'
    query << '*'
    query << "from #{@objectType}"
    query << "limit #{limit}" if limit
    query << ';'
  end.join(' ')
end