Module: LHS::Record::Find::ClassMethods

Defined in:
lib/lhs/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/lhs/concerns/record/find.rb', line 12

def find(*args)
  args, options = process_args(args)
  options = trace!(options)
  raise(LHS::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 if !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