Module: GtfsEngine::Concerns::Controllers::DataAccess

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
lib/gtfs_engine/concerns/controllers/data_access.rb

Instance Method Summary collapse

Instance Method Details

#data(param_key = :data_set_id) ⇒ DataSet

Parameters:

  • param_key (Symbol) (defaults to: :data_set_id)

    The key of the URL param to use as the feed’s ID

Returns:



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gtfs_engine/concerns/controllers/data_access.rb', line 11

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, &blk) ⇒ Object



23
24
25
# File 'lib/gtfs_engine/concerns/controllers/data_access.rb', line 23

def data_cache(key, &blk)
  Rails.cache.fetch("#{data.id}::#{key}", &blk)
end

#param_is_data_set_name?(param_key) ⇒ Bool

instead of its ID

Returns:

  • (Bool)

    true if the key is the name of the GTFS feed,



29
30
31
# File 'lib/gtfs_engine/concerns/controllers/data_access.rb', line 29

def param_is_data_set_name?(param_key)
  !(/[[:digit:]]/ === params[param_key].try(:first))
end