File tree 4 files changed +26
-31
lines changed
4 files changed +26
-31
lines changed Original file line number Diff line number Diff line change 5
5
* [ #2048 ] ( https://github.com/ruby-grape/grape/issues/2034 ) : Grape Enterprise support is now available [ via TideLift] ( https://tidelift.com/subscription/request-a-demo?utm_source=rubygems-grape&utm_medium=referral&utm_campaign=enterprise ) - [ @dblock ] ( https://github.com/dblock ) .
6
6
* [ #2039 ] ( https://github.com/ruby-grape/grape/pull/2039 ) : Travis - update rails versions - [ @ericproulx ] ( https://github.com/ericproulx ) .
7
7
* [ #2038 ] ( https://github.com/ruby-grape/grape/pull/2038 ) : Travis - update ruby versions - [ @ericproulx ] ( https://github.com/ericproulx ) .
8
+ * [ #2050 ] ( https://github.com/ruby-grape/grape/pull/2050 ) : Refactor route public_send to AttributeTranslator - [ @ericproulx ] ( https://github.com/ericproulx ) .
8
9
* Your contribution here.
9
10
10
11
#### Fixes
Original file line number Diff line number Diff line change @@ -7,15 +7,6 @@ module Grape
7
7
class Router
8
8
attr_reader :map , :compiled
9
9
10
- class Any < AttributeTranslator
11
- attr_reader :pattern , :index
12
- def initialize ( pattern , index , **attributes )
13
- @pattern = pattern
14
- @index = index
15
- super ( attributes )
16
- end
17
- end
18
-
19
10
class NormalizePathCache < Grape ::Util ::Cache
20
11
def initialize
21
12
@cache = Hash . new do |h , path |
@@ -64,7 +55,7 @@ def append(route)
64
55
65
56
def associate_routes ( pattern , **options )
66
57
@neutral_regexes << Regexp . new ( "(?<_#{ @neutral_map . length } >)#{ pattern . to_regexp } " )
67
- @neutral_map << Any . new ( pattern , @neutral_map . length , ** options )
58
+ @neutral_map << Grape :: Router :: AttributeTranslator . new ( options . merge ( pattern : pattern , index : @neutral_map . length ) )
68
59
end
69
60
70
61
def call ( env )
Original file line number Diff line number Diff line change @@ -6,10 +6,31 @@ class Router
6
6
class AttributeTranslator
7
7
attr_reader :attributes , :request_method , :requirements
8
8
9
+ ROUTE_ATTRIBUTES = %i[
10
+ prefix
11
+ version
12
+ settings
13
+ format
14
+ description
15
+ http_codes
16
+ headers
17
+ entity
18
+ details
19
+ requirements
20
+ request_method
21
+ namespace
22
+ ] . freeze
23
+
24
+ ROUTER_ATTRIBUTES = %i[ pattern index ] . freeze
25
+
9
26
def initialize ( attributes = { } )
10
27
@attributes = attributes
11
- @request_method = attributes [ :request_method ]
12
- @requirements = attributes [ :requirements ]
28
+ end
29
+
30
+ ( ROUTER_ATTRIBUTES + ROUTE_ATTRIBUTES ) . each do |attr |
31
+ define_method attr do
32
+ attributes [ attr ]
33
+ end
13
34
end
14
35
15
36
def to_h
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ class Route
18
18
19
19
extend Forwardable
20
20
def_delegators :pattern , :path , :origin
21
+ delegate Grape ::Router ::AttributeTranslator ::ROUTE_ATTRIBUTES => :attributes
21
22
22
23
def method_missing ( method_id , *arguments )
23
24
match = ROUTE_ATTRIBUTE_REGEXP . match ( method_id . to_s )
@@ -34,25 +35,6 @@ def respond_to_missing?(method_id, _)
34
35
ROUTE_ATTRIBUTE_REGEXP . match? ( method_id . to_s )
35
36
end
36
37
37
- %i[
38
- prefix
39
- version
40
- settings
41
- format
42
- description
43
- http_codes
44
- headers
45
- entity
46
- details
47
- requirements
48
- request_method
49
- namespace
50
- ] . each do |method_name |
51
- define_method method_name do
52
- attributes . public_send method_name
53
- end
54
- end
55
-
56
38
def route_method
57
39
warn_route_methods ( :method , caller ( 1 ) . shift , :request_method )
58
40
request_method
You can’t perform that action at this time.
0 commit comments