Module: DHS::Record::Find::ClassMethods

Defined in:
lib/dhs/concerns/record/find.rb

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object

Find a single uniqe record

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dhs/concerns/record/find.rb', line 12

def find(*args)
  args, options = process_args(args)
  options = trace!(options)
  raise(DHS::Unprocessable.new, 'Cannot find Record without an ID') if args.blank? && !args.is_a?(Array)
  data =
    if args.present? && args.is_a?(Array)
      find_in_parallel(args, options)
    elsif args.is_a? Hash
      find_with_parameters(args, options)
    else
      find_by_id(args, options)
    end
  return nil if data.nil?
  return data unless data._record
  if data.collection?
    data.map { |record| data._record.new(record.unwrap_nested_item) }
  else
    data._record.new(data.unwrap_nested_item)
  end
end