Module: Crm::Helpers::Finders
- Defined in:
- lib/crm/helpers/finders.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/crm/helpers/finders.rb', line 4 def self.included(base) base.extend self end |
Instance Method Details
#find(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/crm/helpers/finders.rb', line 8 def find(*args) wants_array = args.first.is_a?(Array) ids = args.flatten case ids.size when 0 raise ArgumentError.new('Requires one or more IDs as argument.') when 1 crm_object = find_one(ids.first) wants_array ? [crm_object].compact : crm_object else find_many(ids) end end |
#find_by_query(query, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/crm/helpers/finders.rb', line 23 def find_by_query(query, = {}) limit = [:limit] || 50 sort_order = [:sort_order] || 'desc' crm_class.query(query).limit(limit).sort_order(sort_order).to_a.map do |crm_object| new(crm_object.attributes) end end |