Class: Effective::EventSearch
- Inherits:
-
Object
- Object
- Effective::EventSearch
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/effective/event_search.rb
Constant Summary collapse
- ORDERS =
['Sort by Published Date', 'Sort by Event Date']
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#current_user ⇒ Object
Returns the value of attribute current_user.
-
#order ⇒ Object
Returns the value of attribute order.
-
#term ⇒ Object
Returns the value of attribute term.
-
#unpublished ⇒ Object
Returns the value of attribute unpublished.
Instance Method Summary collapse
-
#collection ⇒ Object
Base collection to search.
-
#events ⇒ Object
The unpaginated results of the search.
- #per_page ⇒ Object
- #present? ⇒ Boolean
-
#results(page: nil) ⇒ Object
The paginated results.
-
#search! ⇒ Object
Search and assigns the collection Assigns the entire collection() if there are no search terms Otherwise validate the search terms.
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
11 12 13 |
# File 'app/models/effective/event_search.rb', line 11 def category @category end |
#current_user ⇒ Object
Returns the value of attribute current_user.
7 8 9 |
# File 'app/models/effective/event_search.rb', line 7 def current_user @current_user end |
#order ⇒ Object
Returns the value of attribute order.
12 13 14 |
# File 'app/models/effective/event_search.rb', line 12 def order @order end |
#term ⇒ Object
Returns the value of attribute term.
10 11 12 |
# File 'app/models/effective/event_search.rb', line 10 def term @term end |
#unpublished ⇒ Object
Returns the value of attribute unpublished.
8 9 10 |
# File 'app/models/effective/event_search.rb', line 8 def unpublished @unpublished end |
Instance Method Details
#collection ⇒ Object
Base collection to search.
18 19 20 |
# File 'app/models/effective/event_search.rb', line 18 def collection Event.events(user: current_user, unpublished: unpublished).upcoming end |
#events ⇒ Object
The unpaginated results of the search
40 41 42 |
# File 'app/models/effective/event_search.rb', line 40 def events @events || collection end |
#per_page ⇒ Object
22 23 24 |
# File 'app/models/effective/event_search.rb', line 22 def per_page (EffectiveEvents.per_page || 24).to_i end |
#present? ⇒ Boolean
26 27 28 |
# File 'app/models/effective/event_search.rb', line 26 def present? term.present? || category.present? || order.present? end |
#results(page: nil) ⇒ Object
The paginated results
45 46 47 48 49 50 |
# File 'app/models/effective/event_search.rb', line 45 def results(page: nil) page = (page || 1).to_i offset = [(page - 1), 0].max * per_page events.limit(per_page).offset(offset) end |
#search! ⇒ Object
Search and assigns the collection Assigns the entire collection() if there are no search terms Otherwise validate the search terms
33 34 35 36 37 |
# File 'app/models/effective/event_search.rb', line 33 def search! @events = build_collection() @events = @events.none if present? && !valid? @events end |