Class: Webhookdb::Service::Collection
- Inherits:
-
Object
- Object
- Webhookdb::Service::Collection
- Extended by:
- MethodUtilities
- Defined in:
- lib/webhookdb/service/collection.rb
Defined Under Namespace
Modules: Helpers
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#last_page ⇒ Object
readonly
Returns the value of attribute last_page.
-
#page_count ⇒ Object
readonly
Returns the value of attribute page_count.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(items, current_page:, page_count:, total_count:, last_page:) ⇒ Collection
constructor
A new instance of Collection.
- #last_page? ⇒ Boolean
- #more? ⇒ Boolean
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_page ⇒ Object (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 |
#items ⇒ Object (readonly)
Returns the value of attribute items.
14 15 16 |
# File 'lib/webhookdb/service/collection.rb', line 14 def items @items end |
#last_page ⇒ Object (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_count ⇒ Object (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_count ⇒ Object (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
41 42 43 |
# File 'lib/webhookdb/service/collection.rb', line 41 def last_page? return @last_page end |
#more? ⇒ Boolean
45 46 47 |
# File 'lib/webhookdb/service/collection.rb', line 45 def more? return !@last_page end |