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 1
1
# frozen_string_literal: true
2
2
3
3
class 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
13
4
end
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 1
1
# frozen_string_literal: true
2
2
3
- class HelloWorldController < ApplicationController
3
+ class HelloWorldController < ActionController ::API
4
+ include DateHeader
5
+
4
6
QUERY_RANGE = 1 ..10_000 # range of IDs in the Fortune DB
5
7
ALL_IDS = QUERY_RANGE . to_a # enumeration of all the IDs in fortune DB
6
8
MIN_QUERIES = 1 # min number of records that can be retrieved
@@ -26,13 +28,6 @@ def cached_query
26
28
render json : items . values
27
29
end
28
30
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
-
36
31
def update
37
32
worlds = ALL_IDS . sample ( query_count ) . map do |id |
38
33
world = World . find ( id )
File renamed without changes.
Original file line number Diff line number Diff line change 46
46
get "json" , to : JsonApp
47
47
get "db" , to : "hello_world#db"
48
48
get "queries" , to : "hello_world#query"
49
- get "fortunes" , to : "hello_world#fortune "
49
+ get "fortunes" , to : "fortunes#index "
50
50
get "updates" , to : "hello_world#update"
51
51
get "plaintext" , to : PlaintextApp
52
52
get "cached" , to : "hello_world#cached_query"
You can’t perform that action at this time.
0 commit comments