Module: Quickbooks::Base::Finders

Included in:
Quickbooks::Base
Defined in:
lib/quickbooks/base/finders.rb

Instance Method Summary collapse

Instance Method Details

#display_name_sql(display_name, options = {}) ⇒ Object



24
25
26
27
28
# File 'lib/quickbooks/base/finders.rb', line 24

def display_name_sql(display_name, options = {})
  options[:select] ||= 'Id, DisplayName'
  where = qbuilder.clause("DisplayName", "=", display_name)
  sql_builder(where, options)
end

#find_by_display_name(display_name, options = {}) ⇒ Object



30
31
32
33
34
# File 'lib/quickbooks/base/finders.rb', line 30

def find_by_display_name(display_name, options = {})
  sql = display_name_sql(display_name, options)
  service = determine_service(options[:entity])
  service.query(sql)
end

#find_by_id(id, model = nil) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/quickbooks/base/finders.rb', line 5

def find_by_id(id, model = nil)
  if model
    new_service = service_for(model)
    new_service.fetch_by_id(id)
  else
    @service.fetch_by_id(id)
  end
end

#qbuilderObject



14
15
16
# File 'lib/quickbooks/base/finders.rb', line 14

def qbuilder
  Quickbooks::Util::QueryBuilder.new
end

#sql_builder(where, options = {}) ⇒ Object



18
19
20
21
22
# File 'lib/quickbooks/base/finders.rb', line 18

def sql_builder(where, options = {})
  options[:entity] ||= entity
  options[:select] ||= '*'
  "SELECT #{options[:select]} FROM #{qbo_case(options[:entity])} WHERE #{where}"
end