File tree Expand file tree Collapse file tree 3 files changed +38
-15
lines changed Expand file tree Collapse file tree 3 files changed +38
-15
lines changed Original file line number Diff line number Diff line change
1
+ * [ #1306 ] ( https://github.com/rubocop/rubocop-rails/pull/1306 ) : Make ` Rails/PluralizationGrammar ` aware of byte methods. ([ @earlopain ] [ ] )
Original file line number Diff line number Diff line change @@ -10,25 +10,39 @@ module Rails
10
10
# # bad
11
11
# 3.day.ago
12
12
# 1.months.ago
13
+ # 5.megabyte
14
+ # 1.gigabyte
13
15
#
14
16
# # good
15
17
# 3.days.ago
16
18
# 1.month.ago
19
+ # 5.megabytes
20
+ # 1.gigabyte
17
21
class PluralizationGrammar < Base
18
22
extend AutoCorrector
19
23
20
- SINGULAR_DURATION_METHODS = { second : :seconds ,
21
- minute : :minutes ,
22
- hour : :hours ,
23
- day : :days ,
24
- week : :weeks ,
25
- fortnight : :fortnights ,
26
- month : :months ,
27
- year : :years } . freeze
28
-
29
- RESTRICT_ON_SEND = SINGULAR_DURATION_METHODS . keys + SINGULAR_DURATION_METHODS . values
30
-
31
- PLURAL_DURATION_METHODS = SINGULAR_DURATION_METHODS . invert . freeze
24
+ SINGULAR_METHODS = {
25
+ second : :seconds ,
26
+ minute : :minutes ,
27
+ hour : :hours ,
28
+ day : :days ,
29
+ week : :weeks ,
30
+ fortnight : :fortnights ,
31
+ month : :months ,
32
+ year : :years ,
33
+ byte : :bytes ,
34
+ kilobyte : :kilobytes ,
35
+ megabyte : :megabytes ,
36
+ gigabyte : :gigabytes ,
37
+ terabyte : :terabytes ,
38
+ petabyte : :petabytes ,
39
+ exabyte : :exabytes ,
40
+ zettabyte : :zettabytes
41
+ } . freeze
42
+
43
+ RESTRICT_ON_SEND = SINGULAR_METHODS . keys + SINGULAR_METHODS . values
44
+
45
+ PLURAL_METHODS = SINGULAR_METHODS . invert . freeze
32
46
33
47
MSG = 'Prefer `%<number>s.%<correct>s`.'
34
48
@@ -86,15 +100,15 @@ def literal_number?(node)
86
100
end
87
101
88
102
def pluralize ( method_name )
89
- SINGULAR_DURATION_METHODS . fetch ( method_name . to_sym ) . to_s
103
+ SINGULAR_METHODS . fetch ( method_name . to_sym ) . to_s
90
104
end
91
105
92
106
def singularize ( method_name )
93
- PLURAL_DURATION_METHODS . fetch ( method_name . to_sym ) . to_s
107
+ PLURAL_METHODS . fetch ( method_name . to_sym ) . to_s
94
108
end
95
109
96
110
def duration_method? ( method_name )
97
- SINGULAR_DURATION_METHODS . key? ( method_name ) || PLURAL_DURATION_METHODS . key? ( method_name )
111
+ SINGULAR_METHODS . key? ( method_name ) || PLURAL_METHODS . key? ( method_name )
98
112
end
99
113
end
100
114
end
Original file line number Diff line number Diff line change 83
83
it_behaves_like 'enforces pluralization grammar' , 'fortnight'
84
84
it_behaves_like 'enforces pluralization grammar' , 'month'
85
85
it_behaves_like 'enforces pluralization grammar' , 'year'
86
+ it_behaves_like 'enforces pluralization grammar' , 'byte'
87
+ it_behaves_like 'enforces pluralization grammar' , 'kilobyte'
88
+ it_behaves_like 'enforces pluralization grammar' , 'megabyte'
89
+ it_behaves_like 'enforces pluralization grammar' , 'gigabyte'
90
+ it_behaves_like 'enforces pluralization grammar' , 'terabyte'
91
+ it_behaves_like 'enforces pluralization grammar' , 'petabyte'
92
+ it_behaves_like 'enforces pluralization grammar' , 'exabyte'
93
+ it_behaves_like 'enforces pluralization grammar' , 'zettabyte'
86
94
end
You can’t perform that action at this time.
0 commit comments