Class: Alchemy::ElementsFinder
- Inherits:
-
Object
- Object
- Alchemy::ElementsFinder
- Defined in:
- lib/alchemy/elements_finder.rb
Overview
Loads elements from given page
Used by Page#find_elements and Alchemy::ElementsHelper#render_elements helper.
If you need custom element loading logic in your views you can create your own finder class and tell the Alchemy::ElementsHelper#render_elements helper or Page#find_elements to use that finder instead of this one.
Instance Method Summary collapse
- #elements(page:) ⇒ ActiveRecord::Relation
-
#initialize(options = {}) ⇒ ElementsFinder
constructor
A new instance of ElementsFinder.
Constructor Details
#initialize(options = {}) ⇒ ElementsFinder
Returns a new instance of ElementsFinder.
31 32 33 |
# File 'lib/alchemy/elements_finder.rb', line 31 def initialize( = {}) @options = end |
Instance Method Details
#elements(page:) ⇒ ActiveRecord::Relation
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/alchemy/elements_finder.rb', line 38 def elements(page:) elements = find_elements(page) if fallback_required?(elements) elements = elements.merge(fallback_elements) end if [:reverse] elements = elements.reverse_order end if [:random] elements = elements.reorder(Arel.sql(random_function)) end elements.offset([:offset]).limit([:count]) end |