Class: RubyLLM::Monitoring::Page

Inherits:
Object
  • Object
show all
Defined in:
app/models/ruby_llm/monitoring/page.rb

Constant Summary collapse

DEFAULT_PAGE_SIZE =
10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(relation, page: 1, page_size: DEFAULT_PAGE_SIZE) ⇒ Page

Returns a new instance of Page.



8
9
10
11
12
# File 'app/models/ruby_llm/monitoring/page.rb', line 8

def initialize(relation, page: 1, page_size: DEFAULT_PAGE_SIZE)
  @relation = relation
  @page_size = page_size
  @index = [ page, 1 ].max
end

Instance Attribute Details

#indexObject (readonly)

Returns the value of attribute index.



6
7
8
# File 'app/models/ruby_llm/monitoring/page.rb', line 6

def index
  @index
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



6
7
8
# File 'app/models/ruby_llm/monitoring/page.rb', line 6

def page_size
  @page_size
end

#recordsObject (readonly)

Returns the value of attribute records.



6
7
8
# File 'app/models/ruby_llm/monitoring/page.rb', line 6

def records
  @records
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/ruby_llm/monitoring/page.rb', line 26

def empty?
  total_count == 0
end

#first?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'app/models/ruby_llm/monitoring/page.rb', line 18

def first?
  index == 1
end

#last?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/models/ruby_llm/monitoring/page.rb', line 22

def last?
  index == pages_count || empty? || records.empty?
end

#next_indexObject



34
35
36
# File 'app/models/ruby_llm/monitoring/page.rb', line 34

def next_index
  pages_count ? [ index + 1, pages_count ].min : index + 1
end

#pages_countObject



38
39
40
# File 'app/models/ruby_llm/monitoring/page.rb', line 38

def pages_count
  (total_count.to_f / page_size).ceil unless total_count.infinite?
end

#previous_indexObject



30
31
32
# File 'app/models/ruby_llm/monitoring/page.rb', line 30

def previous_index
  [ index - 1, 1 ].max
end

#total_countObject



42
43
44
# File 'app/models/ruby_llm/monitoring/page.rb', line 42

def total_count
  @total_count ||= @relation.count # Potentially expensive when filtering a lot of records, with the adapter in charge of doing the filtering in memory
end