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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +2 -3
- data/hanami-utils.gemspec +19 -16
- data/lib/hanami-utils.rb +3 -1
- data/lib/hanami/interactor.rb +47 -21
- data/lib/hanami/logger.rb +6 -6
- data/lib/hanami/logger/colorizer.rb +10 -10
- data/lib/hanami/logger/filter.rb +77 -9
- data/lib/hanami/logger/formatter.rb +4 -4
- data/lib/hanami/utils.rb +8 -6
- data/lib/hanami/utils/basic_object.rb +2 -2
- data/lib/hanami/utils/blank.rb +3 -1
- data/lib/hanami/utils/callbacks.rb +5 -1
- data/lib/hanami/utils/class.rb +7 -7
- data/lib/hanami/utils/class_attribute.rb +4 -2
- data/lib/hanami/utils/deprecation.rb +3 -1
- data/lib/hanami/utils/duplicable.rb +2 -0
- data/lib/hanami/utils/escape.rb +271 -267
- data/lib/hanami/utils/file_list.rb +2 -0
- data/lib/hanami/utils/files.rb +4 -2
- data/lib/hanami/utils/hash.rb +11 -9
- data/lib/hanami/utils/inflector.rb +106 -107
- data/lib/hanami/utils/io.rb +2 -0
- data/lib/hanami/utils/json.rb +4 -2
- data/lib/hanami/utils/kernel.rb +19 -18
- data/lib/hanami/utils/load_paths.rb +4 -2
- data/lib/hanami/utils/path_prefix.rb +6 -4
- data/lib/hanami/utils/shell_color.rb +7 -7
- data/lib/hanami/utils/string.rb +27 -28
- data/lib/hanami/utils/version.rb +3 -1
- metadata +22 -8
data/lib/hanami/utils/files.rb
CHANGED
@@ -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)
|
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 =~ /{/ ?
|
334
|
+
closing = (" " * size) + (target =~ /{/ ? "}" : "end")
|
333
335
|
ending = starting + index(content[starting..-1], path, closing)
|
334
336
|
|
335
337
|
content.slice!(starting..ending)
|
data/lib/hanami/utils/hash.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
|
2
|
-
|
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)
|
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)
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
2
|
-
|
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 =
|
66
|
+
A = "a"
|
65
67
|
|
66
68
|
# @since 0.4.1
|
67
69
|
# @api private
|
68
|
-
CH =
|
70
|
+
CH = "ch"
|
69
71
|
|
70
72
|
# @since 0.4.1
|
71
73
|
# @api private
|
72
|
-
CHES =
|
74
|
+
CHES = "ches"
|
73
75
|
|
74
76
|
# @since 0.4.1
|
75
77
|
# @api private
|
76
|
-
EAUX =
|
78
|
+
EAUX = "eaux"
|
77
79
|
|
78
80
|
# @since 0.6.0
|
79
81
|
# @api private
|
80
|
-
ES =
|
82
|
+
ES = "es"
|
81
83
|
|
82
84
|
# @since 0.4.1
|
83
85
|
# @api private
|
84
|
-
F =
|
86
|
+
F = "f"
|
85
87
|
|
86
88
|
# @since 0.4.1
|
87
89
|
# @api private
|
88
|
-
I =
|
90
|
+
I = "i"
|
89
91
|
|
90
92
|
# @since 0.4.1
|
91
93
|
# @api private
|
92
|
-
ICE =
|
94
|
+
ICE = "ice"
|
93
95
|
|
94
96
|
# @since 0.4.1
|
95
97
|
# @api private
|
96
|
-
ICES =
|
98
|
+
ICES = "ices"
|
97
99
|
|
98
100
|
# @since 0.4.1
|
99
101
|
# @api private
|
100
|
-
IDES =
|
102
|
+
IDES = "ides"
|
101
103
|
|
102
104
|
# @since 0.4.1
|
103
105
|
# @api private
|
104
|
-
IES =
|
106
|
+
IES = "ies"
|
105
107
|
|
106
108
|
# @since 0.4.1
|
107
109
|
# @api private
|
108
|
-
IFE =
|
110
|
+
IFE = "ife"
|
109
111
|
|
110
112
|
# @since 0.4.1
|
111
113
|
# @api private
|
112
|
-
IS =
|
114
|
+
IS = "is"
|
113
115
|
|
114
116
|
# @since 0.4.1
|
115
117
|
# @api private
|
116
|
-
IVES =
|
118
|
+
IVES = "ives"
|
117
119
|
|
118
120
|
# @since 0.4.1
|
119
121
|
# @api private
|
120
|
-
MA =
|
122
|
+
MA = "ma"
|
121
123
|
|
122
124
|
# @since 0.4.1
|
123
125
|
# @api private
|
124
|
-
MATA =
|
126
|
+
MATA = "mata"
|
125
127
|
|
126
128
|
# @since 0.4.1
|
127
129
|
# @api private
|
128
|
-
MEN =
|
130
|
+
MEN = "men"
|
129
131
|
|
130
132
|
# @since 0.4.1
|
131
133
|
# @api private
|
132
|
-
MINA =
|
134
|
+
MINA = "mina"
|
133
135
|
|
134
136
|
# @since 0.6.0
|
135
137
|
# @api private
|
136
|
-
NA =
|
138
|
+
NA = "na"
|
137
139
|
|
138
140
|
# @since 0.6.0
|
139
141
|
# @api private
|
140
|
-
NON =
|
142
|
+
NON = "non"
|
141
143
|
|
142
144
|
# @since 0.4.1
|
143
145
|
# @api private
|
144
|
-
O =
|
146
|
+
O = "o"
|
145
147
|
|
146
148
|
# @since 0.4.1
|
147
149
|
# @api private
|
148
|
-
OES =
|
150
|
+
OES = "oes"
|
149
151
|
|
150
152
|
# @since 0.4.1
|
151
153
|
# @api private
|
152
|
-
OUSE =
|
154
|
+
OUSE = "ouse"
|
153
155
|
|
154
156
|
# @since 0.4.1
|
155
157
|
# @api private
|
156
|
-
RSE =
|
158
|
+
RSE = "rse"
|
157
159
|
|
158
160
|
# @since 0.4.1
|
159
161
|
# @api private
|
160
|
-
RSES =
|
162
|
+
RSES = "rses"
|
161
163
|
|
162
164
|
# @since 0.4.1
|
163
165
|
# @api private
|
164
|
-
S =
|
166
|
+
S = "s"
|
165
167
|
|
166
168
|
# @since 0.4.1
|
167
169
|
# @api private
|
168
|
-
SES =
|
170
|
+
SES = "ses"
|
169
171
|
|
170
172
|
# @since 0.4.1
|
171
173
|
# @api private
|
172
|
-
SSES =
|
174
|
+
SSES = "sses"
|
173
175
|
|
174
176
|
# @since 0.6.0
|
175
177
|
# @api private
|
176
|
-
TA =
|
178
|
+
TA = "ta"
|
177
179
|
|
178
180
|
# @since 0.4.1
|
179
181
|
# @api private
|
180
|
-
UM =
|
182
|
+
UM = "um"
|
181
183
|
|
182
184
|
# @since 0.4.1
|
183
185
|
# @api private
|
184
|
-
US =
|
186
|
+
US = "us"
|
185
187
|
|
186
188
|
# @since 0.4.1
|
187
189
|
# @api private
|
188
|
-
USES =
|
190
|
+
USES = "uses"
|
189
191
|
|
190
192
|
# @since 0.4.1
|
191
193
|
# @api private
|
192
|
-
VES =
|
194
|
+
VES = "ves"
|
193
195
|
|
194
196
|
# @since 0.4.1
|
195
197
|
# @api private
|
196
|
-
X =
|
198
|
+
X = "x"
|
197
199
|
|
198
200
|
# @since 0.4.1
|
199
201
|
# @api private
|
200
|
-
XES =
|
202
|
+
XES = "xes"
|
201
203
|
|
202
204
|
# @since 0.4.1
|
203
205
|
# @api private
|
204
|
-
Y =
|
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
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
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
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
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
|
-
|
248
|
-
|
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
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
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
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
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
|
-
|
489
|
+
|
491
490
|
# rubocop:enable Metrics/PerceivedComplexity
|
492
491
|
end
|
493
492
|
end
|