Module: GtfsEngine::Concerns::Controllers::Gtfs
- Extended by:
- ActiveSupport::Concern
- Included in:
- AgenciesController, GtfsEngine::CalendarDatesController, GtfsEngine::CalendarsController, FareAttributesController, FareRulesController, FeedInfosController, FrequenciesController, RoutesController, ShapesController, StopTimesController, StopsController, TransfersController, TripsController
- Defined in:
- lib/gtfs_engine/concerns/controllers/gtfs.rb
Overview
This file is part of the KNOWtime server.
The KNOWtime server is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
The KNOWtime server is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with the KNOWtime server. If not, see <www.gnu.org/licenses/>.
This controller Concern provides the functionality common among most of the GTFS controllers.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#filter ⇒ ActionController::Parameters
derived from the query string.
-
#index ⇒ Object
GET / collection of elements for the given GTFS type The returned collection may be filtered with query parameters.
-
#show ⇒ Object
GET /:id for a specific element of the given GTFS type.
Instance Method Details
#filter ⇒ ActionController::Parameters
derived from the query string
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gtfs_engine/concerns/controllers/gtfs.rb', line 69 def filter @filter ||= begin query = self.query unknown = query.map do |q, v| query[q] = true if v.blank? # blank value indicates boolean filter filters.include?(q.to_sym) ? nil : q end.compact require 'pry' binding.pry unless unknown.empty? raise GtfsEngine::UnknownFilters.new(unknown), 'unknown filter' end query_params = ActionController::Parameters.new query query_params.permit filters end end |
#index ⇒ Object
GET / collection of elements for the given GTFS type The returned collection may be filtered with query parameters
56 57 58 59 |
# File 'lib/gtfs_engine/concerns/controllers/gtfs.rb', line 56 def index @records = query.empty? ? collection : filtered_collection respond_with @records, template: 'gtfs_engine/gtfs/index' end |
#show ⇒ Object
GET /:id for a specific element of the given GTFS type
62 63 64 65 |
# File 'lib/gtfs_engine/concerns/controllers/gtfs.rb', line 62 def show @record = record respond_with @record, template: 'gtfs_engine/gtfs/show' end |