hanami-utils 1.3.8 → 2.0.0.alpha1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -33
- data/README.md +5 -13
- data/hanami-utils.gemspec +3 -4
- data/lib/hanami/interactor.rb +33 -65
- data/lib/hanami/logger.rb +12 -12
- data/lib/hanami/logger/colorizer.rb +10 -10
- data/lib/hanami/logger/filter.rb +10 -89
- data/lib/hanami/logger/formatter.rb +7 -7
- data/lib/hanami/middleware.rb +11 -0
- data/lib/hanami/utils.rb +3 -19
- data/lib/hanami/utils/basic_object.rb +3 -63
- data/lib/hanami/utils/blank.rb +6 -8
- data/lib/hanami/utils/callbacks.rb +20 -5
- data/lib/hanami/utils/class.rb +3 -52
- data/lib/hanami/utils/class_attribute.rb +22 -13
- data/lib/hanami/utils/class_attribute/attributes.rb +45 -0
- data/lib/hanami/utils/escape.rb +170 -172
- data/lib/hanami/utils/file_list.rb +1 -1
- data/lib/hanami/utils/files.rb +2 -31
- data/lib/hanami/utils/hash.rb +12 -341
- data/lib/hanami/utils/json.rb +1 -1
- data/lib/hanami/utils/kernel.rb +12 -11
- data/lib/hanami/utils/load_paths.rb +3 -3
- data/lib/hanami/utils/query_string.rb +1 -1
- data/lib/hanami/utils/shell_color.rb +9 -9
- data/lib/hanami/utils/string.rb +38 -102
- data/lib/hanami/utils/version.rb +1 -1
- metadata +12 -26
- data/lib/hanami/utils/duplicable.rb +0 -82
- data/lib/hanami/utils/inflector.rb +0 -493
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d4523d52299280469a80451592c55d5771aeaf8e0f93644291f5e9d7a66237a
|
4
|
+
data.tar.gz: 27c144da73fcbd992b4fefdddb9dc1b5be1e58b5abff3fd4078c67f8ec561d43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0e48686597a78927e05bff5da29e0ba0db65f8a03796b36046bb6f84cf35bf964662a87a73bad88bca47096b2b51e737bee0b0545f7341cbbd3579c4e74d4bf
|
7
|
+
data.tar.gz: ebf2deed3ccf571a88ffd151d544254d483f65f26c5bf027c78cbe31220b22afc6b0c9f5b7a6223dd685c553b41fb80c2fe4a7b2a3629d4ab1cdfc5f9293e038
|
data/CHANGELOG.md
CHANGED
@@ -1,41 +1,22 @@
|
|
1
1
|
# Hanami::Utils
|
2
2
|
Ruby core extentions and class utilities for Hanami
|
3
3
|
|
4
|
-
##
|
5
|
-
### Fixed
|
6
|
-
- [Hiếu Nguyễn] Ensure `Hanami::Interactor#initialize` to accept keyword arguments while working with Ruby 3
|
7
|
-
|
8
|
-
## v1.3.7 - 2021-01-04
|
9
|
-
### Added
|
10
|
-
- [Luca Guidi] Official support for Ruby: MRI 3.0
|
11
|
-
- [Khai Le] Allow `Hanami::Logger` to filter sensitive data for an array of hashes
|
12
|
-
|
13
|
-
### Fixed
|
14
|
-
- [Hiếu Nguyễn] Ensure `Hanami::Logger` to not mutate `Hash` input when filtering sensitive data
|
15
|
-
|
16
|
-
## v1.3.6 - 2020-01-07
|
17
|
-
### Added
|
18
|
-
- [Luca Guidi] Official support for Ruby: MRI 2.7
|
19
|
-
|
20
|
-
### Fixed
|
21
|
-
- [ippachi] `Utils::Files.append`: don't check breakline if file is empty
|
22
|
-
|
23
|
-
## v1.3.5 - 2019-10-25
|
24
|
-
### Fixed
|
25
|
-
- [Ivan Kabluchkov] Ensure `Hanami::Logger` filters to not crash when logger stream is a closed tempfile
|
26
|
-
- [Luca Guidi] Ensure `Utils::Files.append` to append contents properly when existing file doesn't end with a newline
|
27
|
-
|
28
|
-
## v1.3.4 - 2019-09-27
|
4
|
+
## v2.0.0.alpha1 - 2019-01-30
|
29
5
|
### Added
|
30
|
-
- [
|
6
|
+
- [Gustavo Caso] Introduce `Hanami::Middleware` namespace
|
7
|
+
- [Luca Guidi] Introduce `Callbacks::Chain#dup`
|
31
8
|
|
32
|
-
|
33
|
-
|
34
|
-
- [
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
- [
|
9
|
+
### Changed
|
10
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
|
11
|
+
- [Luca Guidi] Remove `Utils::Duplicable`
|
12
|
+
- [Luca Guidi] Remove `Utils::Inflector`
|
13
|
+
- [Luca Guidi] Remove `Utils::String.singularize`, and `.pluralize`
|
14
|
+
- [Luca Guidi] Remove `Utils::String#singularize`, and `#pluralize`
|
15
|
+
- [Luca Guidi] Remove instance level interface for `Utils::Hash`
|
16
|
+
- [Luca Guidi] Transform `Utils::Hash` from class to module
|
17
|
+
- [Luca Guidi] Remove `Utils.reload!`
|
18
|
+
- [Gustavo Caso] Remove `Utils::File.rewrite`
|
19
|
+
- [Vladimir Suvorov] Remove `Utils::Class.load_from_pattern!`
|
39
20
|
|
40
21
|
## v1.3.1 - 2019-01-18
|
41
22
|
### Added
|
data/README.md
CHANGED
@@ -5,7 +5,8 @@ Ruby core extensions and class utilities for [Hanami](http://hanamirb.org)
|
|
5
5
|
## Status
|
6
6
|
|
7
7
|
[](https://badge.fury.io/rb/hanami-utils)
|
8
|
-
[](https://travis-ci.org/hanami/utils)
|
9
|
+
[](https://circleci.com/gh/hanami/utils/tree/master)
|
9
10
|
[](https://codecov.io/gh/hanami/utils)
|
10
11
|
[](https://depfu.com/github/hanami/utils?project=Bundler)
|
11
12
|
[](http://inch-ci.org/github/hanami/utils)
|
@@ -21,7 +22,7 @@ Ruby core extensions and class utilities for [Hanami](http://hanamirb.org)
|
|
21
22
|
|
22
23
|
## Rubies
|
23
24
|
|
24
|
-
__Hanami::Utils__ supports Ruby (MRI) 2.
|
25
|
+
__Hanami::Utils__ supports Ruby (MRI) 2.5+
|
25
26
|
|
26
27
|
## Installation
|
27
28
|
|
@@ -78,11 +79,6 @@ Inheritable class attributes. [[API doc](http://www.rubydoc.info/gems/hanami-uti
|
|
78
79
|
|
79
80
|
Deprecate Hanami features. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Deprecation)]
|
80
81
|
|
81
|
-
### Hanami::Utils::Duplicable
|
82
|
-
|
83
|
-
Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Duplicable)]
|
84
|
-
|
85
|
-
|
86
82
|
### Hanami::Utils::Escape
|
87
83
|
|
88
84
|
Safe and fast escape for URLs, HTML content and attributes. Based on OWASP/ESAPI code. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Escape)]
|
@@ -97,16 +93,12 @@ File utilities to manipulate files and directories. [[API doc](http://www.rubydo
|
|
97
93
|
|
98
94
|
### Hanami::Utils::Hash
|
99
95
|
|
100
|
-
|
96
|
+
`Hash` transformations. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Hash)]
|
101
97
|
|
102
98
|
### Hanami::Utils::IO
|
103
99
|
|
104
100
|
Silence Ruby warnings. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/IO)]
|
105
101
|
|
106
|
-
### Hanami::Utils::Inflector
|
107
|
-
|
108
|
-
Complete and customizable english inflections (pluralization and singularization). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Inflector)]
|
109
|
-
|
110
102
|
### Hanami::Utils::Json
|
111
103
|
|
112
104
|
JSON engine with swappable backends (via optional `multi_json` gem) or powered by Ruby's `json` (default). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Json)]
|
@@ -149,6 +141,6 @@ __Hanami::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
149
141
|
|
150
142
|
## Copyright
|
151
143
|
|
152
|
-
Copyright © 2014-
|
144
|
+
Copyright © 2014-2019 Luca Guidi – Released under MIT License
|
153
145
|
|
154
146
|
This project was formerly known as Lotus (`lotus-utils`).
|
data/hanami-utils.gemspec
CHANGED
@@ -18,13 +18,12 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
|
-
spec.required_ruby_version = ">= 2.
|
21
|
+
spec.required_ruby_version = ">= 2.5.0"
|
22
22
|
|
23
23
|
spec.add_dependency "transproc", "~> 1.0"
|
24
24
|
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", ">= 1.6", "< 3"
|
27
|
-
spec.add_development_dependency "rake", "~>
|
28
|
-
spec.add_development_dependency "rspec", "~> 3.
|
29
|
-
spec.add_development_dependency "rubocop", "0.81" # rubocop 0.81+ removed support for Ruby 2.3
|
27
|
+
spec.add_development_dependency "rake", "~> 12"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.7"
|
30
29
|
end
|
data/lib/hanami/interactor.rb
CHANGED
@@ -19,14 +19,14 @@ module Hanami
|
|
19
19
|
# @api private
|
20
20
|
#
|
21
21
|
# @see Hanami::Interactor::Result#respond_to_missing?
|
22
|
-
METHODS = ::Hash[initialize:
|
23
|
-
success?:
|
22
|
+
METHODS = ::Hash[initialize: true,
|
23
|
+
success?: true,
|
24
24
|
successful?: true,
|
25
|
-
failure?:
|
26
|
-
fail!:
|
27
|
-
prepare!:
|
28
|
-
errors:
|
29
|
-
error:
|
25
|
+
failure?: true,
|
26
|
+
fail!: true,
|
27
|
+
prepare!: true,
|
28
|
+
errors: true,
|
29
|
+
error: true].freeze
|
30
30
|
|
31
31
|
# Initialize a new result
|
32
32
|
#
|
@@ -42,7 +42,7 @@ module Hanami
|
|
42
42
|
@success = true
|
43
43
|
end
|
44
44
|
|
45
|
-
#
|
45
|
+
# Check if the current status is successful
|
46
46
|
#
|
47
47
|
# @return [TrueClass,FalseClass] the result of the check
|
48
48
|
#
|
@@ -52,9 +52,9 @@ module Hanami
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# @since 0.3.5
|
55
|
-
|
55
|
+
alias success? successful?
|
56
56
|
|
57
|
-
#
|
57
|
+
# Check if the current status is not successful
|
58
58
|
#
|
59
59
|
# @return [TrueClass,FalseClass] the result of the check
|
60
60
|
#
|
@@ -63,7 +63,7 @@ module Hanami
|
|
63
63
|
!successful?
|
64
64
|
end
|
65
65
|
|
66
|
-
#
|
66
|
+
# Force the status to be a failure
|
67
67
|
#
|
68
68
|
# @since 0.3.5
|
69
69
|
def fail!
|
@@ -106,7 +106,7 @@ module Hanami
|
|
106
106
|
errors.first
|
107
107
|
end
|
108
108
|
|
109
|
-
#
|
109
|
+
# Prepare the result before to be returned
|
110
110
|
#
|
111
111
|
# @param payload [Hash] an updated payload
|
112
112
|
#
|
@@ -181,18 +181,10 @@ module Hanami
|
|
181
181
|
# # ...
|
182
182
|
# end
|
183
183
|
# end
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
@__result = ::Hanami::Interactor::Result.new
|
189
|
-
end
|
190
|
-
else
|
191
|
-
def initialize(*args)
|
192
|
-
super
|
193
|
-
ensure
|
194
|
-
@__result = ::Hanami::Interactor::Result.new
|
195
|
-
end
|
184
|
+
def initialize(*args)
|
185
|
+
super
|
186
|
+
ensure
|
187
|
+
@__result = ::Hanami::Interactor::Result.new
|
196
188
|
end
|
197
189
|
|
198
190
|
# Triggers the operation and return a result.
|
@@ -361,57 +353,33 @@ module Hanami
|
|
361
353
|
# end
|
362
354
|
#
|
363
355
|
# Signup.new.call # => NoMethodError
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
_call(*args, **kwargs) { super }
|
368
|
-
end
|
369
|
-
else
|
370
|
-
def call(*args)
|
371
|
-
@__result = ::Hanami::Interactor::Result.new
|
372
|
-
_call(*args) { super }
|
373
|
-
end
|
356
|
+
def call(*args)
|
357
|
+
@__result = ::Hanami::Interactor::Result.new
|
358
|
+
_call(*args) { super }
|
374
359
|
end
|
375
360
|
|
376
361
|
private
|
377
362
|
|
378
363
|
# @api private
|
379
364
|
# @since 1.1.0
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
yield
|
385
|
-
end
|
386
|
-
|
387
|
-
_prepare!
|
365
|
+
def _call(*args)
|
366
|
+
catch :fail do
|
367
|
+
validate!(*args)
|
368
|
+
yield
|
388
369
|
end
|
389
|
-
else
|
390
|
-
def _call(*args)
|
391
|
-
catch :fail do
|
392
|
-
validate!(*args)
|
393
|
-
yield
|
394
|
-
end
|
395
370
|
|
396
|
-
|
397
|
-
end
|
371
|
+
_prepare!
|
398
372
|
end
|
399
373
|
|
400
374
|
# @since 1.1.0
|
401
|
-
|
402
|
-
|
403
|
-
fail! unless valid?(*args, **kwargs)
|
404
|
-
end
|
405
|
-
else
|
406
|
-
def validate!(*args)
|
407
|
-
fail! unless valid?(*args)
|
408
|
-
end
|
375
|
+
def validate!(*args)
|
376
|
+
fail! unless valid?(*args)
|
409
377
|
end
|
410
378
|
end
|
411
379
|
|
412
380
|
private
|
413
381
|
|
414
|
-
#
|
382
|
+
# Check if proceed with <tt>#call</tt> invokation.
|
415
383
|
# By default it returns <tt>true</tt>.
|
416
384
|
#
|
417
385
|
# Developers can override it.
|
@@ -423,7 +391,7 @@ module Hanami
|
|
423
391
|
true
|
424
392
|
end
|
425
393
|
|
426
|
-
#
|
394
|
+
# Fail and interrupt the current flow.
|
427
395
|
#
|
428
396
|
# @since 0.3.5
|
429
397
|
#
|
@@ -462,7 +430,7 @@ module Hanami
|
|
462
430
|
throw :fail
|
463
431
|
end
|
464
432
|
|
465
|
-
#
|
433
|
+
# Log an error without interrupting the flow.
|
466
434
|
#
|
467
435
|
# When used, the returned result won't be successful.
|
468
436
|
#
|
@@ -517,7 +485,7 @@ module Hanami
|
|
517
485
|
false
|
518
486
|
end
|
519
487
|
|
520
|
-
#
|
488
|
+
# Log an error AND interrupting the flow.
|
521
489
|
#
|
522
490
|
# When used, the returned result won't be successful.
|
523
491
|
#
|
@@ -580,7 +548,7 @@ module Hanami
|
|
580
548
|
# @since 0.5.0
|
581
549
|
# @api private
|
582
550
|
def _exposures
|
583
|
-
Hash[].tap do |result|
|
551
|
+
::Hash[].tap do |result|
|
584
552
|
self.class.exposures.each do |name, ivar|
|
585
553
|
result[name] = instance_variable_defined?(ivar) ? instance_variable_get(ivar) : nil
|
586
554
|
end
|
@@ -613,7 +581,7 @@ module Hanami
|
|
613
581
|
end
|
614
582
|
end
|
615
583
|
|
616
|
-
#
|
584
|
+
# Expose local instance variables into the returning value of <tt>#call</tt>
|
617
585
|
#
|
618
586
|
# @param instance_variable_names [Symbol,Array<Symbol>] one or more instance
|
619
587
|
# variable names
|
@@ -622,7 +590,7 @@ module Hanami
|
|
622
590
|
#
|
623
591
|
# @see Hanami::Interactor::Result
|
624
592
|
#
|
625
|
-
# @example
|
593
|
+
# @example Expose instance variable
|
626
594
|
#
|
627
595
|
# class Signup
|
628
596
|
# 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
|
+
# Implement 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 stand alone (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 support different formatters. Now available only two:
|
34
34
|
#
|
35
35
|
# * Formatter (default)
|
36
36
|
# * JSONFormatter
|
@@ -132,11 +132,11 @@ module Hanami
|
|
132
132
|
# @since 0.8.0
|
133
133
|
# @api private
|
134
134
|
LEVELS = ::Hash[
|
135
|
-
"debug"
|
136
|
-
"info"
|
137
|
-
"warn"
|
138
|
-
"error"
|
139
|
-
"fatal"
|
135
|
+
"debug" => DEBUG,
|
136
|
+
"info" => INFO,
|
137
|
+
"warn" => WARN,
|
138
|
+
"error" => ERROR,
|
139
|
+
"fatal" => FATAL,
|
140
140
|
"unknown" => UNKNOWN
|
141
141
|
].freeze
|
142
142
|
|
@@ -279,9 +279,9 @@ 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/HandleExceptions
|
283
283
|
# rubocop:disable Metrics/ParameterLists
|
284
|
-
def initialize(application_name = nil, *args, stream: $stdout, level: DEBUG, formatter: nil, filter: [], colorizer: nil)
|
284
|
+
def initialize(application_name = nil, *args, stream: $stdout, level: DEBUG, formatter: nil, filter: [], colorizer: nil)
|
285
285
|
begin
|
286
286
|
Utils::Files.mkdir_p(stream)
|
287
287
|
rescue TypeError
|
@@ -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/HandleExceptions
|
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
|
+
# Close the logging stream if this stream isn't an STDOUT
|
317
317
|
#
|
318
318
|
# @since 0.8.0
|
319
319
|
def close
|
@@ -14,9 +14,9 @@ module Hanami
|
|
14
14
|
# @api private
|
15
15
|
def call(app, severity, datetime, _progname)
|
16
16
|
::Hash[
|
17
|
-
app:
|
17
|
+
app: app,
|
18
18
|
severity: severity,
|
19
|
-
time:
|
19
|
+
time: datetime,
|
20
20
|
]
|
21
21
|
end
|
22
22
|
end
|
@@ -44,9 +44,9 @@ module Hanami
|
|
44
44
|
# @return [::Hash] an Hash containing the keys `:app`, `:severity`, and `:time`
|
45
45
|
def call(app, severity, datetime, _progname)
|
46
46
|
::Hash[
|
47
|
-
app:
|
47
|
+
app: app(app),
|
48
48
|
severity: severity(severity),
|
49
|
-
time:
|
49
|
+
time: datetime(datetime),
|
50
50
|
]
|
51
51
|
end
|
52
52
|
|
@@ -57,18 +57,18 @@ module Hanami
|
|
57
57
|
# @since 1.2.0
|
58
58
|
# @api private
|
59
59
|
COLORS = ::Hash[
|
60
|
-
app:
|
60
|
+
app: :blue,
|
61
61
|
datetime: :cyan,
|
62
62
|
].freeze
|
63
63
|
|
64
64
|
# @since 1.2.0
|
65
65
|
# @api private
|
66
66
|
LEVELS = ::Hash[
|
67
|
-
Hanami::Logger::DEBUG
|
68
|
-
Hanami::Logger::INFO
|
69
|
-
Hanami::Logger::WARN
|
70
|
-
Hanami::Logger::ERROR
|
71
|
-
Hanami::Logger::FATAL
|
67
|
+
Hanami::Logger::DEBUG => :cyan,
|
68
|
+
Hanami::Logger::INFO => :magenta,
|
69
|
+
Hanami::Logger::WARN => :yellow,
|
70
|
+
Hanami::Logger::ERROR => :red,
|
71
|
+
Hanami::Logger::FATAL => :red,
|
72
72
|
Hanami::Logger::UNKNOWN => :blue,
|
73
73
|
].freeze
|
74
74
|
|