hanami-utils 1.3.5 → 1.3.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +1 -1
- data/lib/hanami/interactor.rb +10 -10
- data/lib/hanami/logger.rb +6 -6
- data/lib/hanami/utils.rb +4 -4
- data/lib/hanami/utils/basic_object.rb +5 -5
- data/lib/hanami/utils/blank.rb +4 -4
- data/lib/hanami/utils/callbacks.rb +1 -1
- data/lib/hanami/utils/class.rb +1 -1
- data/lib/hanami/utils/escape.rb +4 -4
- data/lib/hanami/utils/file_list.rb +1 -1
- data/lib/hanami/utils/files.rb +11 -1
- data/lib/hanami/utils/hash.rb +13 -13
- data/lib/hanami/utils/inflector.rb +4 -4
- data/lib/hanami/utils/json.rb +1 -1
- data/lib/hanami/utils/kernel.rb +4 -4
- data/lib/hanami/utils/load_paths.rb +2 -2
- data/lib/hanami/utils/query_string.rb +1 -1
- data/lib/hanami/utils/shell_color.rb +2 -2
- data/lib/hanami/utils/string.rb +26 -26
- data/lib/hanami/utils/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e6573938b28f1b4f3b8f46aebec53e487d0af4e85087a65d5e081c4fdc2f030
|
4
|
+
data.tar.gz: e2d13a7d2a675633a7b984882d7c01c5963b3933f1d9339b871ed20838b630c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f8255168597fd310d075400c0a926b28f7bea6dd2025b1572d065e8df7e7ecfa76f991dc88afa1be37b3dfa57b06e70332015018e724ad7731184329a1cab559
|
7
|
+
data.tar.gz: 4ff3e862379db3b02d1fecace8336ed0f44df2b98c9588f807f46883b3b0e7a862beac8119da7428b07484802842b09aca509e1d01ee9dc25360438847d94f63
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Hanami::Utils
|
2
2
|
Ruby core extentions and class utilities for Hanami
|
3
3
|
|
4
|
+
## v1.3.6 - 2020-01-07
|
5
|
+
### Added
|
6
|
+
- [Luca Guidi] Official support for Ruby: MRI 2.7
|
7
|
+
|
8
|
+
### Fixed
|
9
|
+
- [ippachi] `Utils::Files.append`: don't check breakline if file is empty
|
10
|
+
|
4
11
|
## v1.3.5 - 2019-10-25
|
5
12
|
### Fixed
|
6
13
|
- [Ivan Kabluchkov] Ensure `Hanami::Logger` filters to not crash when logger stream is a closed tempfile
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@ Ruby core extensions and class utilities for [Hanami](http://hanamirb.org)
|
|
5
5
|
## Status
|
6
6
|
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/hanami-utils.svg)](https://badge.fury.io/rb/hanami-utils)
|
8
|
-
[![
|
8
|
+
[![Build Status](https://ci.hanamirb.org/api/badges/hanami/utils/status.svg)](https://ci.hanamirb.org/hanami/utils)
|
9
9
|
[![CircleCI](https://circleci.com/gh/hanami/utils/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/utils/tree/master)
|
10
10
|
[![Test Coverage](https://codecov.io/gh/hanami/utils/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/utils)
|
11
11
|
[![Depfu](https://badges.depfu.com/badges/a8545fb67cf32a2c75b6227bc0821027/overview.svg)](https://depfu.com/github/hanami/utils?project=Bundler)
|
data/lib/hanami/interactor.rb
CHANGED
@@ -40,7 +40,7 @@ module Hanami
|
|
40
40
|
@success = true
|
41
41
|
end
|
42
42
|
|
43
|
-
#
|
43
|
+
# Checks if the current status is successful
|
44
44
|
#
|
45
45
|
# @return [TrueClass,FalseClass] the result of the check
|
46
46
|
#
|
@@ -52,7 +52,7 @@ module Hanami
|
|
52
52
|
# @since 0.3.5
|
53
53
|
alias success? successful?
|
54
54
|
|
55
|
-
#
|
55
|
+
# Checks if the current status is not successful
|
56
56
|
#
|
57
57
|
# @return [TrueClass,FalseClass] the result of the check
|
58
58
|
#
|
@@ -61,7 +61,7 @@ module Hanami
|
|
61
61
|
!successful?
|
62
62
|
end
|
63
63
|
|
64
|
-
#
|
64
|
+
# Forces the status to be a failure
|
65
65
|
#
|
66
66
|
# @since 0.3.5
|
67
67
|
def fail!
|
@@ -104,7 +104,7 @@ module Hanami
|
|
104
104
|
errors.first
|
105
105
|
end
|
106
106
|
|
107
|
-
#
|
107
|
+
# Prepares the result before to be returned
|
108
108
|
#
|
109
109
|
# @param payload [Hash] an updated payload
|
110
110
|
#
|
@@ -377,7 +377,7 @@ module Hanami
|
|
377
377
|
|
378
378
|
private
|
379
379
|
|
380
|
-
#
|
380
|
+
# Checks if proceed with <tt>#call</tt> invocation.
|
381
381
|
# By default it returns <tt>true</tt>.
|
382
382
|
#
|
383
383
|
# Developers can override it.
|
@@ -389,7 +389,7 @@ module Hanami
|
|
389
389
|
true
|
390
390
|
end
|
391
391
|
|
392
|
-
#
|
392
|
+
# Fails and interrupts the current flow.
|
393
393
|
#
|
394
394
|
# @since 0.3.5
|
395
395
|
#
|
@@ -428,7 +428,7 @@ module Hanami
|
|
428
428
|
throw :fail
|
429
429
|
end
|
430
430
|
|
431
|
-
#
|
431
|
+
# Logs an error without interrupting the flow.
|
432
432
|
#
|
433
433
|
# When used, the returned result won't be successful.
|
434
434
|
#
|
@@ -483,7 +483,7 @@ module Hanami
|
|
483
483
|
false
|
484
484
|
end
|
485
485
|
|
486
|
-
#
|
486
|
+
# Logs an error and interrupts the flow.
|
487
487
|
#
|
488
488
|
# When used, the returned result won't be successful.
|
489
489
|
#
|
@@ -579,7 +579,7 @@ module Hanami
|
|
579
579
|
end
|
580
580
|
end
|
581
581
|
|
582
|
-
#
|
582
|
+
# Exposes local instance variables into the returning value of <tt>#call</tt>
|
583
583
|
#
|
584
584
|
# @param instance_variable_names [Symbol,Array<Symbol>] one or more instance
|
585
585
|
# variable names
|
@@ -588,7 +588,7 @@ module Hanami
|
|
588
588
|
#
|
589
589
|
# @see Hanami::Interactor::Result
|
590
590
|
#
|
591
|
-
# @example
|
591
|
+
# @example Exposes instance variable
|
592
592
|
#
|
593
593
|
# class Signup
|
594
594
|
# include Hanami::Interactor
|
data/lib/hanami/logger.rb
CHANGED
@@ -7,7 +7,7 @@ require "hanami/utils/files"
|
|
7
7
|
module Hanami
|
8
8
|
# Hanami logger
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# Implementation with the same interface of Ruby std lib `Logger`.
|
11
11
|
# It uses `STDOUT`, `STDERR`, file name or open file as output stream.
|
12
12
|
#
|
13
13
|
#
|
@@ -16,7 +16,7 @@ module Hanami
|
|
16
16
|
#
|
17
17
|
# This is useful for auto-tagging the output. Eg (`app=Booshelf`).
|
18
18
|
#
|
19
|
-
# When used
|
19
|
+
# When used standalone (eg. `Hanami::Logger.info`), it tags lines with `app=Shared`.
|
20
20
|
#
|
21
21
|
#
|
22
22
|
# The available severity levels are the same of `Logger`:
|
@@ -30,7 +30,7 @@ module Hanami
|
|
30
30
|
#
|
31
31
|
# Those levels are available both as class and instance methods.
|
32
32
|
#
|
33
|
-
# Also Hanami::Logger
|
33
|
+
# Also Hanami::Logger supports different formatters. Now available only two:
|
34
34
|
#
|
35
35
|
# * Formatter (default)
|
36
36
|
# * JSONFormatter
|
@@ -279,7 +279,7 @@ module Hanami
|
|
279
279
|
# logger.info "Hello World"
|
280
280
|
#
|
281
281
|
# # => {"app":"Hanami","severity":"DEBUG","time":"2017-03-30T13:57:59Z","message":"Hello World"}
|
282
|
-
# rubocop:disable Lint/
|
282
|
+
# rubocop:disable Lint/SuppressedException
|
283
283
|
# rubocop:disable Metrics/ParameterLists
|
284
284
|
def initialize(application_name = nil, *args, stream: $stdout, level: DEBUG, formatter: nil, filter: [], colorizer: nil)
|
285
285
|
begin
|
@@ -296,7 +296,7 @@ module Hanami
|
|
296
296
|
end
|
297
297
|
|
298
298
|
# rubocop:enable Metrics/ParameterLists
|
299
|
-
# rubocop:enable Lint/
|
299
|
+
# rubocop:enable Lint/SuppressedException
|
300
300
|
|
301
301
|
# Returns the current application name, this is used for tagging purposes
|
302
302
|
#
|
@@ -313,7 +313,7 @@ module Hanami
|
|
313
313
|
super _level(value)
|
314
314
|
end
|
315
315
|
|
316
|
-
#
|
316
|
+
# Closes the logging stream if this stream isn't an STDOUT
|
317
317
|
#
|
318
318
|
# @since 0.8.0
|
319
319
|
def close
|
data/lib/hanami/utils.rb
CHANGED
@@ -21,7 +21,7 @@ module Hanami
|
|
21
21
|
|
22
22
|
# Checks if the current VM is JRuby
|
23
23
|
#
|
24
|
-
# @return [TrueClass,FalseClass]
|
24
|
+
# @return [TrueClass,FalseClass] info whether the VM is JRuby or not
|
25
25
|
#
|
26
26
|
# @since 0.3.1
|
27
27
|
# @api private
|
@@ -31,7 +31,7 @@ module Hanami
|
|
31
31
|
|
32
32
|
# Checks if the current VM is Rubinius
|
33
33
|
#
|
34
|
-
# @return [TrueClass,FalseClass]
|
34
|
+
# @return [TrueClass,FalseClass] info whether the VM is Rubinius or not
|
35
35
|
#
|
36
36
|
# @since 0.3.1
|
37
37
|
# @api private
|
@@ -39,7 +39,7 @@ module Hanami
|
|
39
39
|
RUBY_ENGINE == HANAMI_RUBINIUS
|
40
40
|
end
|
41
41
|
|
42
|
-
# Recursively
|
42
|
+
# Recursively requires Ruby files under the given directory.
|
43
43
|
#
|
44
44
|
# If the directory is relative, it implies it's the path from current directory.
|
45
45
|
# If the directory is absolute, it uses as it is.
|
@@ -54,7 +54,7 @@ module Hanami
|
|
54
54
|
for_each_file_in(directory) { |file| require_relative(file) }
|
55
55
|
end
|
56
56
|
|
57
|
-
# Recursively
|
57
|
+
# Recursively reloads Ruby files under the given directory.
|
58
58
|
#
|
59
59
|
# If the directory is relative, it implies it's the path from current directory.
|
60
60
|
# If the directory is absolute, it uses as it is.
|
@@ -4,7 +4,7 @@ module Hanami
|
|
4
4
|
#
|
5
5
|
# @since 0.3.5
|
6
6
|
class BasicObject < ::BasicObject
|
7
|
-
#
|
7
|
+
# Lookups constants at the top-level namespace, if they are missing in the
|
8
8
|
# current context.
|
9
9
|
#
|
10
10
|
# @param name [Symbol] the constant name
|
@@ -21,7 +21,7 @@ module Hanami
|
|
21
21
|
::Object.const_get(name)
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
24
|
+
# Returns the class for debugging purposes.
|
25
25
|
#
|
26
26
|
# @since 0.3.5
|
27
27
|
#
|
@@ -48,7 +48,7 @@ module Hanami
|
|
48
48
|
|
49
49
|
# @!macro [attach] instance_of?(class)
|
50
50
|
#
|
51
|
-
#
|
51
|
+
# Determines if self is an instance of given class or module
|
52
52
|
#
|
53
53
|
# @param class [Class,Module] the class of module to verify
|
54
54
|
#
|
@@ -63,7 +63,7 @@ module Hanami
|
|
63
63
|
|
64
64
|
# @!macro [attach] is_a?(class)
|
65
65
|
#
|
66
|
-
#
|
66
|
+
# Determines if self is of the type of the object class or module
|
67
67
|
#
|
68
68
|
# @param class [Class,Module] the class of module to verify
|
69
69
|
#
|
@@ -78,7 +78,7 @@ module Hanami
|
|
78
78
|
|
79
79
|
# @!macro [attach] kind_of?(class)
|
80
80
|
#
|
81
|
-
#
|
81
|
+
# Determines if self is of the kind of the object class or module
|
82
82
|
#
|
83
83
|
# @param class [Class,Module] the class of module to verify
|
84
84
|
#
|
data/lib/hanami/utils/blank.rb
CHANGED
@@ -11,7 +11,7 @@ module Hanami
|
|
11
11
|
# @api private
|
12
12
|
STRING_MATCHER = /\A[[:space:]]*\z/.freeze
|
13
13
|
|
14
|
-
# Checks object is blank
|
14
|
+
# Checks if object is blank
|
15
15
|
#
|
16
16
|
# @example Basic Usage
|
17
17
|
# require 'hanami/utils/blank'
|
@@ -25,7 +25,7 @@ module Hanami
|
|
25
25
|
#
|
26
26
|
# @param object the argument
|
27
27
|
#
|
28
|
-
# @return [TrueClass,FalseClass]
|
28
|
+
# @return [TrueClass,FalseClass] info, whether object is blank
|
29
29
|
#
|
30
30
|
# @since 0.8.0
|
31
31
|
# @api private
|
@@ -44,7 +44,7 @@ module Hanami
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
# Checks object is filled
|
47
|
+
# Checks if object is filled
|
48
48
|
#
|
49
49
|
# @example Basic Usage
|
50
50
|
# require 'hanami/utils/blank'
|
@@ -58,7 +58,7 @@ module Hanami
|
|
58
58
|
#
|
59
59
|
# @param object the argument
|
60
60
|
#
|
61
|
-
# @return [TrueClass,FalseClass]
|
61
|
+
# @return [TrueClass,FalseClass] whether the object is filled
|
62
62
|
#
|
63
63
|
# @since 1.0.0
|
64
64
|
# @api private
|
data/lib/hanami/utils/class.rb
CHANGED
data/lib/hanami/utils/escape.rb
CHANGED
@@ -397,7 +397,7 @@ module Hanami
|
|
397
397
|
end
|
398
398
|
end
|
399
399
|
|
400
|
-
#
|
400
|
+
# Escapes HTML contents
|
401
401
|
#
|
402
402
|
# This MUST be used only for tag contents.
|
403
403
|
# Please use `html_attribute` for escaping HTML attributes.
|
@@ -430,7 +430,7 @@ module Hanami
|
|
430
430
|
result
|
431
431
|
end
|
432
432
|
|
433
|
-
#
|
433
|
+
# Escapes HTML attributes
|
434
434
|
#
|
435
435
|
# This can be used both for HTML attributes and contents.
|
436
436
|
# Please note that this is more computational expensive.
|
@@ -463,7 +463,7 @@ module Hanami
|
|
463
463
|
result
|
464
464
|
end
|
465
465
|
|
466
|
-
#
|
466
|
+
# Escapes URL for HTML attributes (href, src, etc..).
|
467
467
|
#
|
468
468
|
# It extracts from the given input the first valid URL that matches the
|
469
469
|
# whitelisted schemes (default: http, https and mailto).
|
@@ -521,7 +521,7 @@ module Hanami
|
|
521
521
|
class << self
|
522
522
|
private
|
523
523
|
|
524
|
-
#
|
524
|
+
# Encodes the given string into UTF-8
|
525
525
|
#
|
526
526
|
# @param input [String] the input
|
527
527
|
#
|
@@ -4,7 +4,7 @@ module Hanami
|
|
4
4
|
#
|
5
5
|
# @since 0.9.0
|
6
6
|
module FileList
|
7
|
-
#
|
7
|
+
# Returns an ordered list of files, consistent across operating systems
|
8
8
|
#
|
9
9
|
# It has the same signature of <tt>Dir.glob</tt>, it just guarantees to
|
10
10
|
# order the results before to return them.
|
data/lib/hanami/utils/files.rb
CHANGED
@@ -163,7 +163,7 @@ module Hanami
|
|
163
163
|
mkdir_p(path)
|
164
164
|
|
165
165
|
content = ::File.readlines(path)
|
166
|
-
content << "\n"
|
166
|
+
content << "\n" if _append_newline?(content)
|
167
167
|
content << "#{contents}\n"
|
168
168
|
|
169
169
|
write(path, content)
|
@@ -452,6 +452,16 @@ module Hanami
|
|
452
452
|
end
|
453
453
|
|
454
454
|
private_class_method :line_number
|
455
|
+
|
456
|
+
# @since 1.3.6
|
457
|
+
# @api private
|
458
|
+
def self._append_newline?(content)
|
459
|
+
return false if content.empty?
|
460
|
+
|
461
|
+
!content.last.end_with?("\n")
|
462
|
+
end
|
463
|
+
|
464
|
+
private_class_method :_append_newline?
|
455
465
|
end
|
456
466
|
end
|
457
467
|
end
|
data/lib/hanami/utils/hash.rb
CHANGED
@@ -47,7 +47,7 @@ module Hanami
|
|
47
47
|
self[:symbolize_keys].call(input)
|
48
48
|
end
|
49
49
|
|
50
|
-
#
|
50
|
+
# Performs deep symbolize on the given hash
|
51
51
|
#
|
52
52
|
# @param input [::Hash] the input
|
53
53
|
#
|
@@ -69,7 +69,7 @@ module Hanami
|
|
69
69
|
self[:deep_symbolize_keys].call(input)
|
70
70
|
end
|
71
71
|
|
72
|
-
#
|
72
|
+
# Stringifies the given hash
|
73
73
|
#
|
74
74
|
# @param input [::Hash] the input
|
75
75
|
#
|
@@ -89,7 +89,7 @@ module Hanami
|
|
89
89
|
self[:stringify_keys].call(input)
|
90
90
|
end
|
91
91
|
|
92
|
-
# Deeply
|
92
|
+
# Deeply stringifies the given hash
|
93
93
|
#
|
94
94
|
# @param input [::Hash] the input
|
95
95
|
#
|
@@ -121,15 +121,15 @@ module Hanami
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
-
# Deep
|
124
|
+
# Deep duplicates hash values
|
125
125
|
#
|
126
|
-
# The output of this function is a
|
126
|
+
# The output of this function is a deep duplicate of the input.
|
127
127
|
# Any further modification on the input, won't be reflected on the output
|
128
128
|
# and viceversa.
|
129
129
|
#
|
130
130
|
# @param input [::Hash] the input
|
131
131
|
#
|
132
|
-
# @return [::Hash] the
|
132
|
+
# @return [::Hash] the deep duplicate of input
|
133
133
|
#
|
134
134
|
# @since 1.0.1
|
135
135
|
#
|
@@ -169,7 +169,7 @@ module Hanami
|
|
169
169
|
end
|
170
170
|
end
|
171
171
|
|
172
|
-
# Deep
|
172
|
+
# Deep serializes given object into a `Hash`
|
173
173
|
#
|
174
174
|
# Please note that the returning `Hash` will use symbols as keys.
|
175
175
|
#
|
@@ -239,7 +239,7 @@ module Hanami
|
|
239
239
|
@hash.default_proc = blk if blk
|
240
240
|
end
|
241
241
|
|
242
|
-
#
|
242
|
+
# Converts in-place all the keys to Symbol instances.
|
243
243
|
#
|
244
244
|
# @return [Hash] self
|
245
245
|
#
|
@@ -263,7 +263,7 @@ module Hanami
|
|
263
263
|
self
|
264
264
|
end
|
265
265
|
|
266
|
-
#
|
266
|
+
# Converts in-place all the keys to Symbol instances, nested hashes are converted too.
|
267
267
|
#
|
268
268
|
# @return [Hash] self
|
269
269
|
#
|
@@ -289,7 +289,7 @@ module Hanami
|
|
289
289
|
self
|
290
290
|
end
|
291
291
|
|
292
|
-
#
|
292
|
+
# Converts in-place all the keys to Symbol instances, nested hashes are converted too.
|
293
293
|
#
|
294
294
|
# @return [Hash] self
|
295
295
|
#
|
@@ -315,7 +315,7 @@ module Hanami
|
|
315
315
|
self
|
316
316
|
end
|
317
317
|
|
318
|
-
#
|
318
|
+
# Returns a deep copy of the current Hanami::Utils::Hash
|
319
319
|
#
|
320
320
|
# @return [Hash] a deep duplicated self
|
321
321
|
#
|
@@ -498,7 +498,7 @@ module Hanami
|
|
498
498
|
@hash.inspect
|
499
499
|
end
|
500
500
|
|
501
|
-
#
|
501
|
+
# Overrides Ruby's method_missing in order to provide ::Hash interface
|
502
502
|
#
|
503
503
|
# @api private
|
504
504
|
# @since 0.3.0
|
@@ -512,7 +512,7 @@ module Hanami
|
|
512
512
|
h
|
513
513
|
end
|
514
514
|
|
515
|
-
#
|
515
|
+
# Overrides Ruby's respond_to_missing? in order to support ::Hash interface
|
516
516
|
#
|
517
517
|
# @api private
|
518
518
|
# @since 0.3.0
|
@@ -314,7 +314,7 @@ module Hanami
|
|
314
314
|
class_eval(&blk)
|
315
315
|
end
|
316
316
|
|
317
|
-
#
|
317
|
+
# Adds a custom inflection exception
|
318
318
|
#
|
319
319
|
# @param [String] singular form
|
320
320
|
# @param [String] plural form
|
@@ -345,7 +345,7 @@ module Hanami
|
|
345
345
|
Inflecto.inflections.irregular(singular, plural)
|
346
346
|
end
|
347
347
|
|
348
|
-
#
|
348
|
+
# Adds an uncountable word
|
349
349
|
#
|
350
350
|
# @param [Array<String>] words
|
351
351
|
#
|
@@ -366,7 +366,7 @@ module Hanami
|
|
366
366
|
end
|
367
367
|
end
|
368
368
|
|
369
|
-
#
|
369
|
+
# Pluralizes the given string
|
370
370
|
#
|
371
371
|
# @param string [String] a string to pluralize
|
372
372
|
#
|
@@ -424,7 +424,7 @@ module Hanami
|
|
424
424
|
# rubocop:enable Metrics/CyclomaticComplexity
|
425
425
|
# rubocop:enable Metrics/MethodLength
|
426
426
|
|
427
|
-
#
|
427
|
+
# Singularizes the given string
|
428
428
|
#
|
429
429
|
# @param string [String] a string to singularize
|
430
430
|
#
|
data/lib/hanami/utils/json.rb
CHANGED
data/lib/hanami/utils/kernel.rb
CHANGED
@@ -7,7 +7,7 @@ require 'hanami/utils'
|
|
7
7
|
require 'hanami/utils/string'
|
8
8
|
|
9
9
|
unless defined?(Boolean)
|
10
|
-
#
|
10
|
+
# Defines top level constant Boolean, so it can be easily used by other libraries
|
11
11
|
# in coercions DSLs
|
12
12
|
#
|
13
13
|
# @since 0.3.0
|
@@ -1021,7 +1021,7 @@ module Hanami
|
|
1021
1021
|
raise TypeError.new "can't convert #{inspect_type_error(arg)}into Symbol"
|
1022
1022
|
end
|
1023
1023
|
|
1024
|
-
#
|
1024
|
+
# Checks if the given argument is a string representation of a number
|
1025
1025
|
#
|
1026
1026
|
# @param arg [Object] the input
|
1027
1027
|
#
|
@@ -1042,11 +1042,11 @@ module Hanami
|
|
1042
1042
|
# @since 0.4.3
|
1043
1043
|
# @api private
|
1044
1044
|
def self.inspect_type_error(arg)
|
1045
|
-
(arg.respond_to?(:inspect) ? arg.inspect : arg.to_s)
|
1045
|
+
(arg.respond_to?(:inspect) ? arg.inspect : arg.to_s) + ' '
|
1046
1046
|
rescue NoMethodError
|
1047
1047
|
# missing the #respond_to? method, fall back to returning the class' name
|
1048
1048
|
begin
|
1049
|
-
arg.class.name
|
1049
|
+
arg.class.name + ' instance '
|
1050
1050
|
rescue NoMethodError
|
1051
1051
|
# missing the #class method, can't fall back to anything better than nothing
|
1052
1052
|
# Callers will have to guess from their code
|
@@ -48,7 +48,7 @@ module Hanami
|
|
48
48
|
@paths = original.instance_variable_get(:@paths).dup
|
49
49
|
end
|
50
50
|
|
51
|
-
# Iterates
|
51
|
+
# Iterates through the collection and yields the given block.
|
52
52
|
# It skips duplications and raises an error in case one of the paths
|
53
53
|
# doesn't exist.
|
54
54
|
#
|
@@ -156,7 +156,7 @@ module Hanami
|
|
156
156
|
|
157
157
|
private
|
158
158
|
|
159
|
-
#
|
159
|
+
# Allows subclasses to define their own policy to discover the realpath
|
160
160
|
# of the given path.
|
161
161
|
#
|
162
162
|
# @since 0.2.0
|
@@ -18,7 +18,7 @@ module Hanami
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
#
|
21
|
+
# Escapes codes for terminals to output strings in colors
|
22
22
|
#
|
23
23
|
# @since 1.2.0
|
24
24
|
# @api private
|
@@ -33,7 +33,7 @@ module Hanami
|
|
33
33
|
gray: 37,
|
34
34
|
].freeze
|
35
35
|
|
36
|
-
#
|
36
|
+
# Colorizes output
|
37
37
|
# 8 colors available: black, red, green, yellow, blue, magenta, cyan, and gray
|
38
38
|
#
|
39
39
|
# @param input [#to_s] the string to colorize
|
data/lib/hanami/utils/string.rb
CHANGED
@@ -79,7 +79,7 @@ module Hanami
|
|
79
79
|
extend Transproc::Registry
|
80
80
|
extend Transproc::Composer
|
81
81
|
|
82
|
-
#
|
82
|
+
# Applies the given transformation(s) to `input`
|
83
83
|
#
|
84
84
|
# It performs a pipeline of transformations, by applying the given functions from `Hanami::Utils::String` and `::String`.
|
85
85
|
# The transformations are applied in the given order.
|
@@ -164,7 +164,7 @@ module Hanami
|
|
164
164
|
binding.instance_exec(value, &fun)
|
165
165
|
end
|
166
166
|
|
167
|
-
#
|
167
|
+
# Returns a titleized version of the string
|
168
168
|
#
|
169
169
|
# @param input [::String] the input
|
170
170
|
#
|
@@ -181,7 +181,7 @@ module Hanami
|
|
181
181
|
underscore(string).split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
|
182
182
|
end
|
183
183
|
|
184
|
-
#
|
184
|
+
# Returns a capitalized version of the string
|
185
185
|
#
|
186
186
|
# @param input [::String] the input
|
187
187
|
#
|
@@ -208,7 +208,7 @@ module Hanami
|
|
208
208
|
tail.unshift(head.capitalize).join(CAPITALIZE_SEPARATOR)
|
209
209
|
end
|
210
210
|
|
211
|
-
#
|
211
|
+
# Returns a CamelCase version of the string
|
212
212
|
#
|
213
213
|
# @param input [::String] the input
|
214
214
|
#
|
@@ -232,7 +232,7 @@ module Hanami
|
|
232
232
|
words.zip(delimiters).join
|
233
233
|
end
|
234
234
|
|
235
|
-
#
|
235
|
+
# Returns a downcased and underscore separated version of the string
|
236
236
|
#
|
237
237
|
# Revised version of `ActiveSupport::Inflector.underscore` implementation
|
238
238
|
# @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
|
@@ -257,7 +257,7 @@ module Hanami
|
|
257
257
|
string.downcase
|
258
258
|
end
|
259
259
|
|
260
|
-
#
|
260
|
+
# Returns a downcased and dash separated version of the string
|
261
261
|
#
|
262
262
|
# @param input [::String] the input
|
263
263
|
#
|
@@ -278,7 +278,7 @@ module Hanami
|
|
278
278
|
underscore(string).split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
|
279
279
|
end
|
280
280
|
|
281
|
-
#
|
281
|
+
# Returns the string without the Ruby namespace of the class
|
282
282
|
#
|
283
283
|
# @param input [::String] the input
|
284
284
|
#
|
@@ -296,7 +296,7 @@ module Hanami
|
|
296
296
|
::String.new(input.to_s).split(NAMESPACE_SEPARATOR).last
|
297
297
|
end
|
298
298
|
|
299
|
-
#
|
299
|
+
# Returns the top level namespace name
|
300
300
|
#
|
301
301
|
# @param input [::String] the input
|
302
302
|
#
|
@@ -314,7 +314,7 @@ module Hanami
|
|
314
314
|
::String.new(input.to_s).split(NAMESPACE_SEPARATOR).first
|
315
315
|
end
|
316
316
|
|
317
|
-
#
|
317
|
+
# Returns a pluralized version of self.
|
318
318
|
#
|
319
319
|
# @param input [::String] the input
|
320
320
|
#
|
@@ -334,7 +334,7 @@ module Hanami
|
|
334
334
|
Inflector.pluralize(string)
|
335
335
|
end
|
336
336
|
|
337
|
-
#
|
337
|
+
# Returns a singularized version of self.
|
338
338
|
#
|
339
339
|
# @param input [::String] the input
|
340
340
|
#
|
@@ -354,7 +354,7 @@ module Hanami
|
|
354
354
|
Inflector.singularize(string)
|
355
355
|
end
|
356
356
|
|
357
|
-
#
|
357
|
+
# Replaces the rightmost match of `pattern` with `replacement`
|
358
358
|
#
|
359
359
|
# If the pattern cannot be matched, it returns the original string.
|
360
360
|
#
|
@@ -396,7 +396,7 @@ module Hanami
|
|
396
396
|
@string = string.to_s
|
397
397
|
end
|
398
398
|
|
399
|
-
#
|
399
|
+
# Returns a titleized version of the string
|
400
400
|
#
|
401
401
|
# @return [Hanami::Utils::String] the transformed string
|
402
402
|
#
|
@@ -412,7 +412,7 @@ module Hanami
|
|
412
412
|
self.class.new underscore.split(CLASSIFY_SEPARATOR).map(&:capitalize).join(TITLEIZE_SEPARATOR)
|
413
413
|
end
|
414
414
|
|
415
|
-
#
|
415
|
+
# Returns a capitalized version of the string
|
416
416
|
#
|
417
417
|
# @return [Hanami::Utils::String] the transformed string
|
418
418
|
#
|
@@ -444,7 +444,7 @@ module Hanami
|
|
444
444
|
)
|
445
445
|
end
|
446
446
|
|
447
|
-
#
|
447
|
+
# Returns a CamelCase version of the string
|
448
448
|
#
|
449
449
|
# @return [Hanami::Utils::String] the transformed string
|
450
450
|
#
|
@@ -467,7 +467,7 @@ module Hanami
|
|
467
467
|
self.class.new words.zip(delimiters).join
|
468
468
|
end
|
469
469
|
|
470
|
-
#
|
470
|
+
# Returns a downcased and underscore separated version of the string
|
471
471
|
#
|
472
472
|
# Revised version of `ActiveSupport::Inflector.underscore` implementation
|
473
473
|
# @see https://github.com/rails/rails/blob/feaa6e2048fe86bcf07e967d6e47b865e42e055b/activesupport/lib/active_support/inflector/methods.rb#L90
|
@@ -491,7 +491,7 @@ module Hanami
|
|
491
491
|
self.class.new new_string
|
492
492
|
end
|
493
493
|
|
494
|
-
#
|
494
|
+
# Returns a downcased and dash separated version of the string
|
495
495
|
#
|
496
496
|
# @return [Hanami::Utils::String] the transformed string
|
497
497
|
#
|
@@ -513,7 +513,7 @@ module Hanami
|
|
513
513
|
self.class.new underscore.split(CLASSIFY_SEPARATOR).join(DASHERIZE_SEPARATOR)
|
514
514
|
end
|
515
515
|
|
516
|
-
#
|
516
|
+
# Returns the string without the Ruby namespace of the class
|
517
517
|
#
|
518
518
|
# @return [Hanami::Utils::String] the transformed string
|
519
519
|
#
|
@@ -532,7 +532,7 @@ module Hanami
|
|
532
532
|
self.class.new split(NAMESPACE_SEPARATOR).last
|
533
533
|
end
|
534
534
|
|
535
|
-
#
|
535
|
+
# Returns the top level namespace name
|
536
536
|
#
|
537
537
|
# @return [Hanami::Utils::String] the transformed string
|
538
538
|
#
|
@@ -590,7 +590,7 @@ module Hanami
|
|
590
590
|
end
|
591
591
|
# rubocop:enable Metrics/MethodLength
|
592
592
|
|
593
|
-
#
|
593
|
+
# Returns a pluralized version of self.
|
594
594
|
#
|
595
595
|
# @return [Hanami::Utils::String] the pluralized string.
|
596
596
|
#
|
@@ -603,7 +603,7 @@ module Hanami
|
|
603
603
|
self.class.new Inflector.pluralize(self)
|
604
604
|
end
|
605
605
|
|
606
|
-
#
|
606
|
+
# Returns a singularized version of self.
|
607
607
|
#
|
608
608
|
# @return [Hanami::Utils::String] the singularized string.
|
609
609
|
#
|
@@ -650,7 +650,7 @@ module Hanami
|
|
650
650
|
|
651
651
|
alias eql? ==
|
652
652
|
|
653
|
-
#
|
653
|
+
# Splits the string with the given pattern
|
654
654
|
#
|
655
655
|
# @return [Array<::String>]
|
656
656
|
#
|
@@ -662,7 +662,7 @@ module Hanami
|
|
662
662
|
@string.split(pattern, limit)
|
663
663
|
end
|
664
664
|
|
665
|
-
#
|
665
|
+
# Replaces the given pattern with the given replacement
|
666
666
|
#
|
667
667
|
# @return [::String]
|
668
668
|
#
|
@@ -678,7 +678,7 @@ module Hanami
|
|
678
678
|
end
|
679
679
|
end
|
680
680
|
|
681
|
-
#
|
681
|
+
# Iterates through the string, matching the pattern.
|
682
682
|
# Either return all those patterns, or pass them to the block.
|
683
683
|
#
|
684
684
|
# @return [Array<::String>]
|
@@ -691,7 +691,7 @@ module Hanami
|
|
691
691
|
@string.scan(pattern, &blk)
|
692
692
|
end
|
693
693
|
|
694
|
-
#
|
694
|
+
# Replaces the rightmost match of `pattern` with `replacement`
|
695
695
|
#
|
696
696
|
# If the pattern cannot be matched, it returns the original string.
|
697
697
|
#
|
@@ -726,7 +726,7 @@ module Hanami
|
|
726
726
|
end
|
727
727
|
end
|
728
728
|
|
729
|
-
#
|
729
|
+
# Overrides Ruby's method_missing in order to provide ::String interface
|
730
730
|
#
|
731
731
|
# @api private
|
732
732
|
# @since 0.3.0
|
@@ -740,7 +740,7 @@ module Hanami
|
|
740
740
|
s
|
741
741
|
end
|
742
742
|
|
743
|
-
#
|
743
|
+
# Overrides Ruby's respond_to_missing? in order to support ::String interface
|
744
744
|
#
|
745
745
|
# @api private
|
746
746
|
# @since 0.3.0
|
data/lib/hanami/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: transproc
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
- !ruby/object:Gem::Version
|
145
145
|
version: '0'
|
146
146
|
requirements: []
|
147
|
-
rubygems_version: 3.
|
147
|
+
rubygems_version: 3.1.2
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: Ruby core extentions and Hanami utilities
|