Sha256: 4f63c53533aa159006e0fb4b64ab51537c5c5664122e0e6c92e495d6adfe13fd
Contents?: true
Size: 789 Bytes
Versions: 2
Compression:
Stored size: 789 Bytes
Contents
module ActiveForce module Finders module ClassMethods def find_by conditions query = self.query query_conditions(conditions).each do |query_condition| query = query.where query_condition end send_query(query).first end private #maps a hash key => value to a string 'key = value' def query_conditions conditions conditions.map do |key, value| "#{ mappings[key] } = #{ enclose_value value }" end end # encloses the value in quotes if it's a string def enclose_value value if value.is_a? String "'#{value}'" else value.to_s end end end def self.included mod mod.extend ClassMethods end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_force-0.3.2 | lib/active_force/finders.rb |
active_force-0.3.1 | lib/active_force/finders.rb |