module GtfsEngine::Concerns::Controllers::DataAccess

A Controller Concern for convenient access to the DataSet specified in the URL.

Public Instance Methods

data(param_key=:data_set_id) click to toggle source

@param param_key <Symbol> The key of the URL param to use as the feed’s ID @return <DataSet>

# File lib/gtfs_engine/concerns/controllers/data_access.rb, line 8
def data(param_key=:data_set_id)
  key = params[param_key]
  (@data_sets ||= {})[key] =
      Rails.cache.fetch "data_set_#{key}" do
        if param_is_data_set_name? param_key
          GtfsEngine::DataSet.where(name: key).newest
        else
          GtfsEngine::DataSet.find params[param_key]
        end
      end
end
data_cache(key) { || ... } click to toggle source
# File lib/gtfs_engine/concerns/controllers/data_access.rb, line 20
def data_cache(key)
  Rails.cache.fetch "#{data.id}::#{key}" do
    yield
  end
end
param_is_data_set_name?(param_key) click to toggle source

@return <Bool> true if the key is the name of the GTFS feed,

instead of its ID
# File lib/gtfs_engine/concerns/controllers/data_access.rb, line 28
def param_is_data_set_name?(param_key)
  not /[[:digit:]]/ === params[param_key].try(:first)
end