Class: ForestAdminDatasourceToolkit::Components::Query::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/forest_admin_datasource_toolkit/components/query/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(offset:, limit:) ⇒ Page

Returns a new instance of Page.



7
8
9
10
# File 'lib/forest_admin_datasource_toolkit/components/query/page.rb', line 7

def initialize(offset:, limit:)
  @offset = offset
  @limit = limit
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



5
6
7
# File 'lib/forest_admin_datasource_toolkit/components/query/page.rb', line 5

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



5
6
7
# File 'lib/forest_admin_datasource_toolkit/components/query/page.rb', line 5

def offset
  @offset
end

Instance Method Details

#apply(records) ⇒ Object



12
13
14
15
# File 'lib/forest_admin_datasource_toolkit/components/query/page.rb', line 12

def apply(records)
  end_index = @limit ? @offset + @limit : nil
  records[@offset...end_index]
end

#to_hObject



17
18
19
# File 'lib/forest_admin_datasource_toolkit/components/query/page.rb', line 17

def to_h
  { offset: @offset, limit: @limit }
end