Sha256: 30a8259941713f2a6d44007ae05a85dae709d1f36d6e746c48bf8f91960f2621

Contents?: true

Size: 939 Bytes

Versions: 207

Compression:

Stored size: 939 Bytes

Contents

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

    def initialize(items, total, current_page)
      @items = items
      @total = total
      @current_page = 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

207 entries across 207 versions & 3 rubygems

Version Path
neo4j-9.6.2 lib/neo4j/paginated.rb
activegraph-10.0.0.pre.alpha.11 lib/neo4j/paginated.rb
activegraph-10.0.0.pre.alpha.10 lib/neo4j/paginated.rb
activegraph-10.0.0.pre.alpha.9 lib/neo4j/paginated.rb
activegraph-10.0.0.pre.alpha.8 lib/neo4j/paginated.rb
activegraph-10.0.0.pre.alpha.7 lib/neo4j/paginated.rb
activegraph-10.0.0.pre.alpha.6 lib/neo4j/paginated.rb
neo4j-10.0.0.pre.alpha.5 lib/neo4j/paginated.rb
neo4j-10.0.0.pre.alpha.4 lib/neo4j/paginated.rb
neo4j-10.0.0.pre.alpha.3 lib/neo4j/paginated.rb
neo4j-10.0.0.pre.alpha.2 lib/neo4j/paginated.rb
neo4j-10.0.0.pre.alpha.1 lib/neo4j/paginated.rb
neo4j-9.6.1 lib/neo4j/paginated.rb
neo4j-9.6.0 lib/neo4j/paginated.rb
neo4j-9.5.3 lib/neo4j/paginated.rb
neo4j-9.5.2 lib/neo4j/paginated.rb
neo4j-9.5.0 lib/neo4j/paginated.rb
neo4j-9.4.0 lib/neo4j/paginated.rb
neo4j-9.3.0 lib/neo4j/paginated.rb
neo4j-9.2.4 lib/neo4j/paginated.rb