Class: Webhookdb::Service::Collection

Inherits:
Object
  • Object
show all
Extended by:
MethodUtilities
Defined in:
lib/webhookdb/service/collection.rb

Defined Under Namespace

Modules: Helpers

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MethodUtilities

attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias, singleton_predicate_accessor, singleton_predicate_reader

Constructor Details

#initialize(items, current_page:, page_count:, total_count:, last_page:) ⇒ Collection

Returns a new instance of Collection.



33
34
35
36
37
38
39
# File 'lib/webhookdb/service/collection.rb', line 33

def initialize(items, current_page:, page_count:, total_count:, last_page:)
  @items = items
  @current_page = current_page
  @page_count = page_count
  @last_page = last_page
  @total_count = total_count
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



14
15
16
# File 'lib/webhookdb/service/collection.rb', line 14

def current_page
  @current_page
end

#itemsObject (readonly)

Returns the value of attribute items.



14
15
16
# File 'lib/webhookdb/service/collection.rb', line 14

def items
  @items
end

#last_pageObject (readonly)

Returns the value of attribute last_page.



14
15
16
# File 'lib/webhookdb/service/collection.rb', line 14

def last_page
  @last_page
end

#page_countObject (readonly)

Returns the value of attribute page_count.



14
15
16
# File 'lib/webhookdb/service/collection.rb', line 14

def page_count
  @page_count
end

#total_countObject (readonly)

Returns the value of attribute total_count.



14
15
16
# File 'lib/webhookdb/service/collection.rb', line 14

def total_count
  @total_count
end

Class Method Details

.from_array(array) ⇒ Object



29
30
31
# File 'lib/webhookdb/service/collection.rb', line 29

def self.from_array(array)
  return self.new(array, current_page: 1, page_count: 1, total_count: array.size, last_page: true)
end

.from_dataset(ds) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webhookdb/service/collection.rb', line 16

def self.from_dataset(ds)
  if ds.respond_to?(:current_page)
    return self.new(
      ds.all,
      current_page: ds.current_page,
      page_count: ds.page_count,
      total_count: ds.pagination_record_count,
      last_page: ds.last_page?,
    )
  end
  return self.from_array(ds.all)
end

Instance Method Details

#last_page?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/webhookdb/service/collection.rb', line 41

def last_page?
  return @last_page
end

#more?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/webhookdb/service/collection.rb', line 45

def more?
  return !@last_page
end