File tree Expand file tree Collapse file tree 6 files changed +31
-18
lines changed
Expand file tree Collapse file tree 6 files changed +31
-18
lines changed Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33class ApplicationController < ActionController ::Base
4- if defined? ( Agoo ) || defined? ( Falcon ) || defined? ( Puma )
5- before_action :add_date_header
6- end
7-
8- private
9-
10- def add_date_header
11- response . set_header ( 'Date' , Time . now . httpdate )
12- end
134end
Original file line number Diff line number Diff line change 1+ module DateHeader
2+ extend ActiveSupport ::Concern
3+
4+ included do
5+ if defined? ( Agoo ) || defined? ( Falcon ) || defined? ( Puma )
6+ before_action :add_header
7+ end
8+ end
9+
10+ private
11+
12+ def add_header
13+ response . set_header ( 'Date' , Time . now . httpdate )
14+ end
15+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ class FortunesController < ApplicationController
4+ include DateHeader
5+
6+ def index
7+ @fortunes = Fortune . all . to_a
8+ @fortunes << Fortune . new ( id : 0 , message : 'Additional fortune added at request time.' )
9+ @fortunes . sort_by! ( &:message )
10+ render :fortune
11+ end
12+ end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
3- class HelloWorldController < ApplicationController
3+ class HelloWorldController < ActionController ::API
4+ include DateHeader
5+
46 QUERY_RANGE = 1 ..10_000 # range of IDs in the Fortune DB
57 ALL_IDS = QUERY_RANGE . to_a # enumeration of all the IDs in fortune DB
68 MIN_QUERIES = 1 # min number of records that can be retrieved
@@ -26,13 +28,6 @@ def cached_query
2628 render json : items . values
2729 end
2830
29- def fortune
30- @fortunes = Fortune . all . to_a
31- @fortunes << Fortune . new ( id : 0 , message : 'Additional fortune added at request time.' )
32- @fortunes . sort_by! ( &:message )
33- render :fortune
34- end
35-
3631 def update
3732 worlds = ALL_IDS . sample ( query_count ) . map do |id |
3833 world = World . find ( id )
File renamed without changes.
Original file line number Diff line number Diff line change 4646 get "json" , to : JsonApp
4747 get "db" , to : "hello_world#db"
4848 get "queries" , to : "hello_world#query"
49- get "fortunes" , to : "hello_world#fortune "
49+ get "fortunes" , to : "fortunes#index "
5050 get "updates" , to : "hello_world#update"
5151 get "plaintext" , to : PlaintextApp
5252 get "cached" , to : "hello_world#cached_query"
You can’t perform that action at this time.
0 commit comments