hanami-utils 1.3.6 → 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hanami
2
4
  module Utils
3
5
  # Ordered file list, consistent across operating systems
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "pathname"
2
4
  require "fileutils"
3
5
  require "hanami/utils/deprecation"
@@ -324,12 +326,12 @@ module Hanami
324
326
  #
325
327
  # # class App
326
328
  # # end
327
- def self.remove_block(path, target) # rubocop:disable Metrics/AbcSize
329
+ def self.remove_block(path, target)
328
330
  content = ::File.readlines(path)
329
331
  starting = index(content, path, target)
330
332
  line = content[starting]
331
333
  size = line[/\A[[:space:]]*/].bytesize
332
- closing = (" " * size) + (target =~ /{/ ? '}' : 'end')
334
+ closing = (" " * size) + (target =~ /{/ ? "}" : "end")
333
335
  ending = starting + index(content[starting..-1], path, closing)
334
336
 
335
337
  content.slice!(starting..ending)
@@ -1,12 +1,13 @@
1
- require 'hanami/utils/duplicable'
2
- require 'transproc'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/duplicable"
4
+ require "transproc"
3
5
 
4
6
  module Hanami
5
7
  module Utils
6
8
  # Hash on steroids
7
9
  # @since 0.1.0
8
10
  #
9
- # rubocop:disable Metrics/ClassLength
10
11
  class Hash
11
12
  # @since 0.6.0
12
13
  # @api private
@@ -105,7 +106,7 @@ module Hanami
105
106
  #
106
107
  # hash.class
107
108
  # # => Hash
108
- def self.deep_stringify(input) # rubocop:disable Metrics/MethodLength
109
+ def self.deep_stringify(input)
109
110
  input.each_with_object({}) do |(key, value), output|
110
111
  output[key.to_s] =
111
112
  case value
@@ -193,7 +194,7 @@ module Hanami
193
194
  #
194
195
  # Hanami::Utils::Hash.deep_serialize(input)
195
196
  # # => {:foo=>"bar", :baz=>[{:hello=>"world"}]}
196
- def self.deep_serialize(input) # rubocop:disable Metrics/MethodLength
197
+ def self.deep_serialize(input)
197
198
  input.to_hash.each_with_object({}) do |(key, value), output|
198
199
  output[key.to_sym] =
199
200
  case value
@@ -452,7 +453,7 @@ module Hanami
452
453
  end
453
454
  end
454
455
 
455
- alias to_hash to_h
456
+ alias_method :to_hash, :to_h
456
457
 
457
458
  # Converts into a nested array of [ key, value ] arrays.
458
459
  #
@@ -476,7 +477,7 @@ module Hanami
476
477
  @hash == other.to_h
477
478
  end
478
479
 
479
- alias eql? ==
480
+ alias_method :eql?, :==
480
481
 
481
482
  # Returns the hash of the internal @hash
482
483
  #
@@ -505,7 +506,9 @@ module Hanami
505
506
  #
506
507
  # @raise [NoMethodError] If doesn't respond to the given method
507
508
  def method_missing(method_name, *args, &blk)
508
- raise NoMethodError.new(%(undefined method `#{method_name}' for #{@hash}:#{self.class})) unless respond_to?(method_name)
509
+ unless respond_to?(method_name)
510
+ raise NoMethodError.new(%(undefined method `#{method_name}' for #{@hash}:#{self.class}))
511
+ end
509
512
 
510
513
  h = @hash.__send__(method_name, *args, &blk)
511
514
  h = self.class.new(h) if h.is_a?(::Hash)
@@ -520,6 +523,5 @@ module Hanami
520
523
  @hash.respond_to?(method_name, include_private)
521
524
  end
522
525
  end
523
- # rubocop:enable Metrics/ClassLength
524
526
  end
525
527
  end
@@ -1,5 +1,7 @@
1
- require 'hanami/utils/class_attribute'
2
- require 'hanami/utils/blank'
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/utils/class_attribute"
4
+ require "hanami/utils/blank"
3
5
 
4
6
  module Hanami
5
7
  module Utils
@@ -61,147 +63,147 @@ module Hanami
61
63
 
62
64
  # @since 0.4.1
63
65
  # @api private
64
- A = 'a'.freeze
66
+ A = "a"
65
67
 
66
68
  # @since 0.4.1
67
69
  # @api private
68
- CH = 'ch'.freeze
70
+ CH = "ch"
69
71
 
70
72
  # @since 0.4.1
71
73
  # @api private
72
- CHES = 'ches'.freeze
74
+ CHES = "ches"
73
75
 
74
76
  # @since 0.4.1
75
77
  # @api private
76
- EAUX = 'eaux'.freeze
78
+ EAUX = "eaux"
77
79
 
78
80
  # @since 0.6.0
79
81
  # @api private
80
- ES = 'es'.freeze
82
+ ES = "es"
81
83
 
82
84
  # @since 0.4.1
83
85
  # @api private
84
- F = 'f'.freeze
86
+ F = "f"
85
87
 
86
88
  # @since 0.4.1
87
89
  # @api private
88
- I = 'i'.freeze
90
+ I = "i"
89
91
 
90
92
  # @since 0.4.1
91
93
  # @api private
92
- ICE = 'ice'.freeze
94
+ ICE = "ice"
93
95
 
94
96
  # @since 0.4.1
95
97
  # @api private
96
- ICES = 'ices'.freeze
98
+ ICES = "ices"
97
99
 
98
100
  # @since 0.4.1
99
101
  # @api private
100
- IDES = 'ides'.freeze
102
+ IDES = "ides"
101
103
 
102
104
  # @since 0.4.1
103
105
  # @api private
104
- IES = 'ies'.freeze
106
+ IES = "ies"
105
107
 
106
108
  # @since 0.4.1
107
109
  # @api private
108
- IFE = 'ife'.freeze
110
+ IFE = "ife"
109
111
 
110
112
  # @since 0.4.1
111
113
  # @api private
112
- IS = 'is'.freeze
114
+ IS = "is"
113
115
 
114
116
  # @since 0.4.1
115
117
  # @api private
116
- IVES = 'ives'.freeze
118
+ IVES = "ives"
117
119
 
118
120
  # @since 0.4.1
119
121
  # @api private
120
- MA = 'ma'.freeze
122
+ MA = "ma"
121
123
 
122
124
  # @since 0.4.1
123
125
  # @api private
124
- MATA = 'mata'.freeze
126
+ MATA = "mata"
125
127
 
126
128
  # @since 0.4.1
127
129
  # @api private
128
- MEN = 'men'.freeze
130
+ MEN = "men"
129
131
 
130
132
  # @since 0.4.1
131
133
  # @api private
132
- MINA = 'mina'.freeze
134
+ MINA = "mina"
133
135
 
134
136
  # @since 0.6.0
135
137
  # @api private
136
- NA = 'na'.freeze
138
+ NA = "na"
137
139
 
138
140
  # @since 0.6.0
139
141
  # @api private
140
- NON = 'non'.freeze
142
+ NON = "non"
141
143
 
142
144
  # @since 0.4.1
143
145
  # @api private
144
- O = 'o'.freeze
146
+ O = "o"
145
147
 
146
148
  # @since 0.4.1
147
149
  # @api private
148
- OES = 'oes'.freeze
150
+ OES = "oes"
149
151
 
150
152
  # @since 0.4.1
151
153
  # @api private
152
- OUSE = 'ouse'.freeze
154
+ OUSE = "ouse"
153
155
 
154
156
  # @since 0.4.1
155
157
  # @api private
156
- RSE = 'rse'.freeze
158
+ RSE = "rse"
157
159
 
158
160
  # @since 0.4.1
159
161
  # @api private
160
- RSES = 'rses'.freeze
162
+ RSES = "rses"
161
163
 
162
164
  # @since 0.4.1
163
165
  # @api private
164
- S = 's'.freeze
166
+ S = "s"
165
167
 
166
168
  # @since 0.4.1
167
169
  # @api private
168
- SES = 'ses'.freeze
170
+ SES = "ses"
169
171
 
170
172
  # @since 0.4.1
171
173
  # @api private
172
- SSES = 'sses'.freeze
174
+ SSES = "sses"
173
175
 
174
176
  # @since 0.6.0
175
177
  # @api private
176
- TA = 'ta'.freeze
178
+ TA = "ta"
177
179
 
178
180
  # @since 0.4.1
179
181
  # @api private
180
- UM = 'um'.freeze
182
+ UM = "um"
181
183
 
182
184
  # @since 0.4.1
183
185
  # @api private
184
- US = 'us'.freeze
186
+ US = "us"
185
187
 
186
188
  # @since 0.4.1
187
189
  # @api private
188
- USES = 'uses'.freeze
190
+ USES = "uses"
189
191
 
190
192
  # @since 0.4.1
191
193
  # @api private
192
- VES = 'ves'.freeze
194
+ VES = "ves"
193
195
 
194
196
  # @since 0.4.1
195
197
  # @api private
196
- X = 'x'.freeze
198
+ X = "x"
197
199
 
198
200
  # @since 0.4.1
199
201
  # @api private
200
- XES = 'xes'.freeze
202
+ XES = "xes"
201
203
 
202
204
  # @since 0.4.1
203
205
  # @api private
204
- Y = 'y'.freeze
206
+ Y = "y"
205
207
 
206
208
  include Utils::ClassAttribute
207
209
 
@@ -212,40 +214,40 @@ module Hanami
212
214
  class_attribute :plurals
213
215
  self.plurals = IrregularRules.new(
214
216
  # irregular
215
- 'cactus' => 'cacti',
216
- 'child' => 'children',
217
- 'corpus' => 'corpora',
218
- 'foot' => 'feet',
219
- 'genus' => 'genera',
220
- 'goose' => 'geese',
221
- 'louse' => 'lice',
222
- 'man' => 'men',
223
- 'mouse' => 'mice',
224
- 'ox' => 'oxen',
225
- 'person' => 'people',
226
- 'quiz' => 'quizzes',
227
- 'sex' => 'sexes',
228
- 'testis' => 'testes',
229
- 'tooth' => 'teeth',
230
- 'woman' => 'women',
217
+ "cactus" => "cacti",
218
+ "child" => "children",
219
+ "corpus" => "corpora",
220
+ "foot" => "feet",
221
+ "genus" => "genera",
222
+ "goose" => "geese",
223
+ "louse" => "lice",
224
+ "man" => "men",
225
+ "mouse" => "mice",
226
+ "ox" => "oxen",
227
+ "person" => "people",
228
+ "quiz" => "quizzes",
229
+ "sex" => "sexes",
230
+ "testis" => "testes",
231
+ "tooth" => "teeth",
232
+ "woman" => "women",
231
233
  # uncountable
232
- 'deer' => 'deer',
233
- 'equipment' => 'equipment',
234
- 'fish' => 'fish',
235
- 'information' => 'information',
236
- 'means' => 'means',
237
- 'money' => 'money',
238
- 'news' => 'news',
239
- 'offspring' => 'offspring',
240
- 'rice' => 'rice',
241
- 'series' => 'series',
242
- 'sheep' => 'sheep',
243
- 'species' => 'species',
244
- 'police' => 'police',
234
+ "deer" => "deer",
235
+ "equipment" => "equipment",
236
+ "fish" => "fish",
237
+ "information" => "information",
238
+ "means" => "means",
239
+ "money" => "money",
240
+ "news" => "news",
241
+ "offspring" => "offspring",
242
+ "rice" => "rice",
243
+ "series" => "series",
244
+ "sheep" => "sheep",
245
+ "species" => "species",
246
+ "police" => "police",
245
247
  # regressions
246
248
  # https://github.com/hanami/utils/issues/106
247
- 'album' => 'albums',
248
- 'area' => 'areas'
249
+ "album" => "albums",
250
+ "area" => "areas"
249
251
  )
250
252
 
251
253
  # Irregular rules for singulars
@@ -255,42 +257,42 @@ module Hanami
255
257
  class_attribute :singulars
256
258
  self.singulars = IrregularRules.new(
257
259
  # irregular
258
- 'cacti' => 'cactus',
259
- 'children' => 'child',
260
- 'corpora' => 'corpus',
261
- 'feet' => 'foot',
262
- 'genera' => 'genus',
263
- 'geese' => 'goose',
264
- 'lice' => 'louse',
265
- 'men' => 'man',
266
- 'mice' => 'mouse',
267
- 'oxen' => 'ox',
268
- 'people' => 'person',
269
- 'quizzes' => 'quiz',
270
- 'sexes' => 'sex',
271
- 'testes' => 'testis',
272
- 'teeth' => 'tooth',
273
- 'women' => 'woman',
260
+ "cacti" => "cactus",
261
+ "children" => "child",
262
+ "corpora" => "corpus",
263
+ "feet" => "foot",
264
+ "genera" => "genus",
265
+ "geese" => "goose",
266
+ "lice" => "louse",
267
+ "men" => "man",
268
+ "mice" => "mouse",
269
+ "oxen" => "ox",
270
+ "people" => "person",
271
+ "quizzes" => "quiz",
272
+ "sexes" => "sex",
273
+ "testes" => "testis",
274
+ "teeth" => "tooth",
275
+ "women" => "woman",
274
276
  # uncountable
275
- 'deer' => 'deer',
276
- 'equipment' => 'equipment',
277
- 'fish' => 'fish',
278
- 'information' => 'information',
279
- 'means' => 'means',
280
- 'money' => 'money',
281
- 'news' => 'news',
282
- 'offspring' => 'offspring',
283
- 'rice' => 'rice',
284
- 'series' => 'series',
285
- 'sheep' => 'sheep',
286
- 'species' => 'species',
287
- 'police' => 'police',
277
+ "deer" => "deer",
278
+ "equipment" => "equipment",
279
+ "fish" => "fish",
280
+ "information" => "information",
281
+ "means" => "means",
282
+ "money" => "money",
283
+ "news" => "news",
284
+ "offspring" => "offspring",
285
+ "rice" => "rice",
286
+ "series" => "series",
287
+ "sheep" => "sheep",
288
+ "species" => "species",
289
+ "police" => "police",
288
290
  # fallback
289
- 'areas' => 'area',
290
- 'hives' => 'hive',
291
- 'phases' => 'phase',
292
- 'exercises' => 'exercise',
293
- 'releases' => 'release'
291
+ "areas" => "area",
292
+ "hives" => "hive",
293
+ "phases" => "phase",
294
+ "exercises" => "exercise",
295
+ "releases" => "release"
294
296
  )
295
297
 
296
298
  # Block for custom inflection rules.
@@ -377,7 +379,6 @@ module Hanami
377
379
  #
378
380
  # rubocop:disable Metrics/AbcSize
379
381
  # rubocop:disable Metrics/CyclomaticComplexity
380
- # rubocop:disable Metrics/MethodLength
381
382
  # rubocop:disable Style/PerlBackrefs
382
383
  def self.pluralize(string)
383
384
  return string if string.nil? || string =~ Utils::Blank::STRING_MATCHER
@@ -422,7 +423,6 @@ module Hanami
422
423
  # rubocop:enable Style/PerlBackrefs
423
424
  # rubocop:enable Metrics/AbcSize
424
425
  # rubocop:enable Metrics/CyclomaticComplexity
425
- # rubocop:enable Metrics/MethodLength
426
426
 
427
427
  # Singularizes the given string
428
428
  #
@@ -435,7 +435,6 @@ module Hanami
435
435
  #
436
436
  # rubocop:disable Metrics/AbcSize
437
437
  # rubocop:disable Metrics/CyclomaticComplexity
438
- # rubocop:disable Metrics/MethodLength
439
438
  # rubocop:disable Metrics/PerceivedComplexity
440
439
  # rubocop:disable Style/PerlBackrefs
441
440
  def self.singularize(string)
@@ -487,7 +486,7 @@ module Hanami
487
486
  # rubocop:enable Style/PerlBackrefs
488
487
  # rubocop:enable Metrics/AbcSize
489
488
  # rubocop:enable Metrics/CyclomaticComplexity
490
- # rubocop:enable Metrics/MethodLength
489
+
491
490
  # rubocop:enable Metrics/PerceivedComplexity
492
491
  end
493
492
  end