Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
# frozen_string_literal: true

class ApplicationController < ActionController::Base
if defined?(Agoo) || defined?(Falcon) || defined?(Puma)
before_action :add_date_header
end

private

def add_date_header
response.set_header('Date', Time.now.httpdate)
end
end
15 changes: 15 additions & 0 deletions frameworks/Ruby/rails/app/controllers/concerns/date_header.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module DateHeader
extend ActiveSupport::Concern

included do
if defined?(Agoo) || defined?(Falcon) || defined?(Puma)
before_action :add_header
end
end

private

def add_header
response.set_header('Date', Time.now.httpdate)
end
end
12 changes: 12 additions & 0 deletions frameworks/Ruby/rails/app/controllers/fortunes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class FortunesController < ApplicationController
include DateHeader

def index
@fortunes = Fortune.all.to_a
@fortunes << Fortune.new(id: 0, message: 'Additional fortune added at request time.')
@fortunes.sort_by!(&:message)
render :fortune
end
end
11 changes: 3 additions & 8 deletions frameworks/Ruby/rails/app/controllers/hello_world_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class HelloWorldController < ApplicationController
class HelloWorldController < ActionController::API
include DateHeader

QUERY_RANGE = 1..10_000 # range of IDs in the Fortune DB
ALL_IDS = QUERY_RANGE.to_a # enumeration of all the IDs in fortune DB
MIN_QUERIES = 1 # min number of records that can be retrieved
Expand All @@ -26,13 +28,6 @@ def cached_query
render json: items.values
end

def fortune
@fortunes = Fortune.all.to_a
@fortunes << Fortune.new(id: 0, message: 'Additional fortune added at request time.')
@fortunes.sort_by!(&:message)
render :fortune
end

def update
worlds = ALL_IDS.sample(query_count).map do |id|
world = World.find(id)
Expand Down
2 changes: 1 addition & 1 deletion frameworks/Ruby/rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
get "json", to: JsonApp
get "db", to: "hello_world#db"
get "queries", to: "hello_world#query"
get "fortunes", to: "hello_world#fortune"
get "fortunes", to: "fortunes#index"
get "updates", to: "hello_world#update"
get "plaintext", to: PlaintextApp
get "cached", to: "hello_world#cached_query"
Expand Down
Loading