Module: LHS::Record::Last::ClassMethods

Defined in:
lib/lhs/concerns/record/last.rb

Instance Method Summary collapse

Instance Method Details

#last(options = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/lhs/concerns/record/last.rb', line 11

def last(options = nil)
  first_batch = find_by({}, options).parent
  if first_batch.paginated?
    pagination = first_batch._pagination
    find_by({ pagination_key => pagination.class.page_to_offset(pagination.last_page, pagination.limit) }, options)
  else
    first_batch.last
  end
end

#last!(options = nil) ⇒ Object



21
22
23
# File 'lib/lhs/concerns/record/last.rb', line 21

def last!(options = nil)
  find_by!({}, options)
end