Sha256: d4729be6a7da28ac604dbf2dfdc54f3e5f13c98ee44abe2d10fae884b15bdfb5

Contents?: true

Size: 584 Bytes

Versions: 14

Compression:

Stored size: 584 Bytes

Contents

# frozen_string_literal: true

require 'active_support'

class LHS::Record

  module Last
    extend ActiveSupport::Concern

    module ClassMethods
      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

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lhs-19.1.0 lib/lhs/concerns/record/last.rb
lhs-19.0.2 lib/lhs/concerns/record/last.rb
lhs-19.0.1 lib/lhs/concerns/record/last.rb
lhs-19.0.0 lib/lhs/concerns/record/last.rb
lhs-19.0.0.pre.endpoint.1 lib/lhs/concerns/record/last.rb
lhs-18.0.3 lib/lhs/concerns/record/last.rb
lhs-18.0.2 lib/lhs/concerns/record/last.rb
lhs-18.0.1 lib/lhs/concerns/record/last.rb
lhs-18.0.0 lib/lhs/concerns/record/last.rb
lhs-17.0.1 lib/lhs/concerns/record/last.rb
lhs-17.0.1.pre1 lib/lhs/concerns/record/last.rb
lhs-18.0.0.pre.pre1 lib/lhs/concerns/record/last.rb
lhs-17.0.0 lib/lhs/concerns/record/last.rb
lhs-16.1.6 lib/lhs/concerns/record/last.rb