Sha256: eb6eb6ad16a2b9ca62773de6098b687f324161bd2e11a517dae068f17fd01596

Contents?: true

Size: 927 Bytes

Versions: 6

Compression:

Stored size: 927 Bytes

Contents

module Neo4j
  class Paginated
    include Enumerable
    attr_reader :items, :total, :current_page

    def initialize(items, total, current_page)
      @items, @total, @current_page = items, total, current_page
    end

    def self.create_from(source, page, per_page, order = nil)
      target = source.node_var || source.identity
      partial = source.skip((page - 1) * per_page).limit(per_page)
      ordered_partial, ordered_source = if order
                                          [partial.order_by(order), source.query.with("#{target} as #{target}").pluck("COUNT(#{target})").first]
                                        else
                                          [partial, source.count]
                                        end
      Paginated.new(ordered_partial, ordered_source, page)
    end

    delegate :each, to: :items
    delegate :pluck, to: :items
    delegate :size, :[], to: :items
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
neo4j-4.1.5 lib/neo4j/paginated.rb
neo4j-4.1.4 lib/neo4j/paginated.rb
neo4j-4.1.3 lib/neo4j/paginated.rb
neo4j-4.1.2 lib/neo4j/paginated.rb
neo4j-4.1.1 lib/neo4j/paginated.rb
neo4j-4.1.0 lib/neo4j/paginated.rb