Class: CursorPager::LimitRelation

Inherits:
Object
  • Object
show all
Defined in:
lib/cursor_pager/limit_relation.rb

Overview

Applies first and last limits to a relation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_relation, first, last) ⇒ LimitRelation

Returns a new instance of LimitRelation.



8
9
10
11
12
# File 'lib/cursor_pager/limit_relation.rb', line 8

def initialize(base_relation, first, last)
  @base_relation = base_relation
  @first = first
  @last = last
end

Instance Attribute Details

#base_relationObject (readonly)

Returns the value of attribute base_relation.



6
7
8
# File 'lib/cursor_pager/limit_relation.rb', line 6

def base_relation
  @base_relation
end

#firstObject (readonly)

Returns the value of attribute first.



6
7
8
# File 'lib/cursor_pager/limit_relation.rb', line 6

def first
  @first
end

#lastObject (readonly)

Returns the value of attribute last.



6
7
8
# File 'lib/cursor_pager/limit_relation.rb', line 6

def last
  @last
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
# File 'lib/cursor_pager/limit_relation.rb', line 14

def call
  relation = base_relation

  relation = apply_first(relation) if first.present?
  relation = apply_last(relation) if last.present?

  relation
end