Sha256: f0d97eab66985c85a687c35f4545067d9b300a9516f797ff99e8f2ba4032b1d2

Contents?: true

Size: 945 Bytes

Versions: 42

Compression:

Stored size: 945 Bytes

Contents

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

42 entries across 42 versions & 1 rubygems

Version Path
activegraph-10.1.1 lib/active_graph/paginated.rb
activegraph-11.0.1-java lib/active_graph/paginated.rb
activegraph-11.0.0-java lib/active_graph/paginated.rb
activegraph-10.1.0 lib/active_graph/paginated.rb
activegraph-11.0.0.beta.4-java lib/active_graph/paginated.rb
activegraph-10.0.2 lib/active_graph/paginated.rb
activegraph-11.0.0.beta.3-java lib/active_graph/paginated.rb
activegraph-11.0.0.beta.2-java lib/active_graph/paginated.rb
activegraph-11.0.0.beta.1-java lib/active_graph/paginated.rb
activegraph-10.0.1 lib/active_graph/paginated.rb
activegraph-10.0.0 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.11 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.10 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.9 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.8 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.7 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.6 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.5 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.4 lib/active_graph/paginated.rb
activegraph-10.0.0.pre.beta.3 lib/active_graph/paginated.rb