Module: FacilitiesQuery
- Defined in:
- app/models/facilities_query.rb,
app/models/facilities_query/base.rb,
app/models/facilities_query/ids_query.rb,
app/models/facilities_query/zip_query.rb,
app/models/facilities_query/state_query.rb,
app/models/facilities_query/radial_query.rb,
app/models/facilities_query/bounding_box_query.rb
Defined Under Namespace
Classes: Base, BoundingBoxQuery, IdsQuery, RadialQuery, StateQuery, ZipQuery
Class Method Summary collapse
-
.generate_query(params) ⇒ Object
When given more than one type of distance query param, return nil because the app will not choose preference for the user.
Class Method Details
.generate_query(params) ⇒ Object
When given more than one type of distance query param, return nil because the app will not choose preference for the user. In the controller, this logic is somewhat duplicated and will render an error when given multiple params. In the case that only one of these types is given, return the class used to make that type of query.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/facilities_query.rb', line 10 def self.generate_query(params) location_keys = (%i[lat long state zip bbox] & params.keys.map(&:to_sym)) case location_keys when %i[lat long] RadialQuery.new(params) when [:state] StateQuery.new(params) when [:zip] ZipQuery.new(params) when [:bbox] BoundingBoxQuery.new(params) else params[:ids].present? ? IdsQuery.new(params) : Base.new(params) end end |