Class: GtfsEngine::DataSetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/gtfs_engine/data_sets_controller.rb

Instance Method Summary collapse

Methods included from Concerns::Controllers::DataAccess

#data, #data_cache, #param_is_data_set_name?

Instance Method Details

#indexObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/gtfs_engine/data_sets_controller.rb', line 5

def index
  expires_in(3.hours)

  @data_sets = Rails.cache.fetch('data_sets_index') do
    {}.tap do |sets|
      DataSet.order(:created_at).each do |set|
        (sets[set.name] ||= []) << set
      end
    end
  end

  dates = @data_sets.values.flatten.collect(&:created_at)
  respond_with(@data_sets) if stale?(last_modified: dates.max, public: true)
end

#showObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/gtfs_engine/data_sets_controller.rb', line 20

def show
  expires_in(2.hours)

  @data_set = data(:id)

  # Set location if the given id is a data-source name and not an ID
  if param_is_data_set_name?(:id)
    respond_with(@data_set, location: data_set_url(@data_set))
  else
    respond_with(@data_set)
  end
end