Module: GtfsEngine::Concerns::Controllers::Gtfs

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#filterActionController::Parameters

derived from the query string

Returns:

  • (ActionController::Parameters)

    the map of fields to filter;



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gtfs_engine/concerns/controllers/gtfs.rb', line 52

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

    unless unknown.empty?
      raise GtfsEngine::UnknownFilters.new(unknown), 'unknown filter'
    end

    query_params = ActionController::Parameters.new query
    query_params.permit filters
  end
end

#indexObject

GET / collection of elements for the given GTFS type The returned collection may be filtered with query parameters



39
40
41
42
# File 'lib/gtfs_engine/concerns/controllers/gtfs.rb', line 39

def index
  @records = query.empty? ? collection : filtered_collection
  respond_with @records, template: 'gtfs_engine/gtfs/index'
end

#showObject

GET /:id for a specific element of the given GTFS type



45
46
47
48
# File 'lib/gtfs_engine/concerns/controllers/gtfs.rb', line 45

def show
  @record = record
  respond_with @record, template: 'gtfs_engine/gtfs/show'
end