Class: BaseFinder
- Inherits:
-
Object
- Object
- BaseFinder
- Defined in:
- lib/abstract_finder/base_finder.rb
Overview
Class Base finder
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_PER_PAGE =
10
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(filters) ⇒ BaseFinder
constructor
A new instance of BaseFinder.
- #meta ⇒ Object
- #page ⇒ Object
- #per_page ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(filters) ⇒ BaseFinder
Returns a new instance of BaseFinder.
13 14 15 |
# File 'lib/abstract_finder/base_finder.rb', line 13 def initialize(filters) @filters = filters end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
5 6 7 |
# File 'lib/abstract_finder/base_finder.rb', line 5 def collection @collection end |
Class Method Details
.call(*args) ⇒ Object
7 8 9 10 11 |
# File 'lib/abstract_finder/base_finder.rb', line 7 def self.call(*args) instance = new(*args) instance.call instance end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 |
# File 'lib/abstract_finder/base_finder.rb', line 17 def call load_collection self end |
#meta ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/abstract_finder/base_finder.rb', line 37 def { page: page, per_page: per_page, total: @total, next_page: (@total - (page * per_page + per_page)).positive? } end |
#page ⇒ Object
23 24 25 |
# File 'lib/abstract_finder/base_finder.rb', line 23 def page filter_by(:page)&.to_i || 1 end |
#per_page ⇒ Object
27 28 29 |
# File 'lib/abstract_finder/base_finder.rb', line 27 def per_page filter_by(:per_page)&.to_i || DEFAULT_PER_PAGE end |
#total ⇒ Object
31 32 33 34 35 |
# File 'lib/abstract_finder/base_finder.rb', line 31 def total return 0 if @collection.blank? @total ||= @collection.size end |