class ActiveForce::ActiveQuery
Attributes
sobject[R]
Public Class Methods
new(sobject)
click to toggle source
Calls superclass method
# File lib/active_force/active_query.rb, line 14 def initialize sobject @sobject = sobject super table_name fields sobject.fields end
Public Instance Methods
count()
click to toggle source
Calls superclass method
# File lib/active_force/active_query.rb, line 26 def count super sfdc_client.query(to_s).first.expr0 end
find_by(conditions)
click to toggle source
# File lib/active_force/active_query.rb, line 47 def find_by conditions where(conditions).limit 1 end
includes(*relations)
click to toggle source
# File lib/active_force/active_query.rb, line 51 def includes(*relations) relations.each do |relation| association = sobject.associations[relation] fields Association::EagerLoadProjectionBuilder.build association end self end
limit(limit)
click to toggle source
Calls superclass method
# File lib/active_force/active_query.rb, line 31 def limit limit super limit == 1 ? to_a.first : self end
none()
click to toggle source
# File lib/active_force/active_query.rb, line 59 def none @records = [] where(id: '1'*18).where(id: '0'*18) end
select(*fields)
click to toggle source
Calls superclass method
# File lib/active_force/active_query.rb, line 42 def select *fields fields.map! { |field| mappings[field] } super *fields end
to_a()
click to toggle source
# File lib/active_force/active_query.rb, line 20 def to_a @records ||= result.to_a.map { |mash| build mash } end
Also aliased as: all
where(args=nil, *rest)
click to toggle source
Calls superclass method
# File lib/active_force/active_query.rb, line 36 def where args=nil, *rest return self if args.nil? super build_condition args, rest self end
Private Instance Methods
applicable_predicate(attribute, value)
click to toggle source
# File lib/active_force/active_query.rb, line 118 def applicable_predicate(attribute, value) if value.is_a? Array in_predicate attribute, value else eq_predicate attribute, value end end
build_condition(args, other=[])
click to toggle source
# File lib/active_force/active_query.rb, line 66 def build_condition(args, other=[]) case args when String, Array build_condition_from_array other.empty? ? args : ([args] + other) when Hash build_conditions_from_hash args else args end end
build_condition_from_array(ary)
click to toggle source
# File lib/active_force/active_query.rb, line 77 def build_condition_from_array(ary) statement, *bind_parameters = ary return statement if bind_parameters.empty? if bind_parameters.first.is_a? Hash replace_named_bind_parameters statement, bind_parameters.first else replace_bind_parameters statement, bind_parameters end end
build_conditions_from_hash(hash)
click to toggle source
# File lib/active_force/active_query.rb, line 112 def build_conditions_from_hash(hash) hash.map do |key, value| applicable_predicate mappings[key], value end end
enclose_value(value)
click to toggle source
# File lib/active_force/active_query.rb, line 135 def enclose_value value case value when String "'#{quote_string(value)}'" when NilClass 'NULL' else value.to_s end end
eq_predicate(attribute, value)
click to toggle source
# File lib/active_force/active_query.rb, line 131 def eq_predicate(attribute, value) "#{attribute} = #{enclose_value value}" end
in_predicate(attribute, values)
click to toggle source
# File lib/active_force/active_query.rb, line 126 def in_predicate(attribute, values) escaped_values = values.map &method(:enclose_value) "#{attribute} IN (#{escaped_values.join(',')})" end
quote_string(s)
click to toggle source
# File lib/active_force/active_query.rb, line 146 def quote_string(s) # From activerecord/lib/active_record/connection_adapters/abstract/quoting.rb, version 4.1.5, line 82 s.gsub(/\\/, '\&\&').gsub(/'/, "''") end
raise_if_bind_arity_mismatch(expected_var_count, actual_var_count)
click to toggle source
# File lib/active_force/active_query.rb, line 106 def raise_if_bind_arity_mismatch(expected_var_count, actual_var_count) if expected_var_count != actual_var_count raise PreparedStatementInvalid, "wrong number of bind variables (#{actual_var_count} for #{expected_var_count})" end end
replace_bind_parameters(statement, values)
click to toggle source
# File lib/active_force/active_query.rb, line 98 def replace_bind_parameters(statement, values) raise_if_bind_arity_mismatch statement.count('?'), values.size bound = values.dup statement.gsub('?') do enclose_value bound.shift end end
replace_named_bind_parameters(statement, bind_parameters)
click to toggle source
# File lib/active_force/active_query.rb, line 87 def replace_named_bind_parameters(statement, bind_parameters) statement.gsub(/(:?):([a-zA-Z]\w*)/) do key = $2.to_sym if bind_parameters.has_key? key enclose_value bind_parameters[key] else raise PreparedStatementInvalid, "missing value for :#{key} in #{statement}" end end end
result()
click to toggle source
# File lib/active_force/active_query.rb, line 151 def result sfdc_client.query(self.to_s) end