Class: Pagy::Cursor
Instance Attribute Summary collapse
-
#after ⇒ Object
readonly
Returns the value of attribute after.
-
#arel_table ⇒ Object
readonly
Returns the value of attribute arel_table.
-
#before ⇒ Object
readonly
Returns the value of attribute before.
-
#comparation ⇒ Object
readonly
Returns the value of attribute comparation.
-
#has_more ⇒ Object
(also: #has_more?)
Returns the value of attribute has_more.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#primary_key ⇒ Object
readonly
Returns the value of attribute primary_key.
Instance Method Summary collapse
-
#initialize(vars) ⇒ Cursor
constructor
A new instance of Cursor.
Constructor Details
#initialize(vars) ⇒ Cursor
Returns a new instance of Cursor.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 8 def initialize(vars) @vars = VARS.merge(vars.delete_if{|_,v| v.nil? || v == '' }) @items = vars[:items] || VARS[:items] @before = vars[:before] @after = vars[:after] @arel_table = vars[:arel_table] @primary_key = vars[:primary_key] @reorder = vars[:order] || {} if @before.present? and @after.present? raise(ArgumentError, 'before and after can not be both mentioned') end if vars[:backend] == 'uuid' @comparation = 'lt' # arel table less than @position = @before @order = @reorder.merge({ :created_at => :desc , @primary_key => :desc }) if @after.present? || (@reorder.present? && @reorder.values.uniq.first.to_sym == :asc) @comparation = 'gt' # arel table greater than @position = @after @order = @reorder.merge({ :created_at => :asc , @primary_key => :asc }) end else @comparation = 'lt' @position = @before @order = @reorder.merge({ @primary_key => :desc }) if @after.present? || (@reorder.present? && @reorder.values.uniq.first.to_sym == :asc) @comparation = 'gt' @position = @after @order = @reorder.merge({ @primary_key => :asc }) end end end |
Instance Attribute Details
#after ⇒ Object (readonly)
Returns the value of attribute after.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def after @after end |
#arel_table ⇒ Object (readonly)
Returns the value of attribute arel_table.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def arel_table @arel_table end |
#before ⇒ Object (readonly)
Returns the value of attribute before.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def before @before end |
#comparation ⇒ Object (readonly)
Returns the value of attribute comparation.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def comparation @comparation end |
#has_more ⇒ Object Also known as: has_more?
Returns the value of attribute has_more.
5 6 7 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 5 def has_more @has_more end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def order @order end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def position @position end |
#primary_key ⇒ Object (readonly)
Returns the value of attribute primary_key.
4 5 6 |
# File 'lib/pagy_cursor/pagy/cursor.rb', line 4 def primary_key @primary_key end |