hanami-utils 1.3.5 → 2.0.0.alpha2
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 +41 -0
- data/README.md +5 -15
- data/hanami-utils.gemspec +19 -16
- data/lib/hanami-utils.rb +3 -1
- data/lib/hanami/interactor.rb +70 -36
- data/lib/hanami/logger.rb +13 -13
- data/lib/hanami/logger/colorizer.rb +10 -10
- data/lib/hanami/logger/filter.rb +74 -9
- data/lib/hanami/logger/formatter.rb +7 -7
- data/lib/hanami/middleware.rb +11 -0
- data/lib/hanami/utils.rb +12 -26
- data/lib/hanami/utils/basic_object.rb +7 -7
- data/lib/hanami/utils/blank.rb +9 -9
- data/lib/hanami/utils/callbacks.rb +24 -3
- data/lib/hanami/utils/class.rb +3 -56
- data/lib/hanami/utils/class_attribute.rb +23 -12
- data/lib/hanami/utils/class_attribute/attributes.rb +45 -0
- data/lib/hanami/utils/deprecation.rb +3 -1
- data/lib/hanami/utils/escape.rb +275 -271
- data/lib/hanami/utils/file_list.rb +24 -2
- data/lib/hanami/utils/files.rb +16 -22
- data/lib/hanami/utils/hash.rb +24 -363
- data/lib/hanami/utils/io.rb +2 -0
- data/lib/hanami/utils/json.rb +5 -3
- data/lib/hanami/utils/kernel.rb +22 -21
- data/lib/hanami/utils/load_paths.rb +6 -4
- data/lib/hanami/utils/path_prefix.rb +38 -6
- data/lib/hanami/utils/query_string.rb +1 -1
- data/lib/hanami/utils/shell_color.rb +9 -9
- data/lib/hanami/utils/string.rb +44 -470
- data/lib/hanami/utils/version.rb +3 -1
- metadata +30 -16
- data/lib/hanami/utils/duplicable.rb +0 -80
- data/lib/hanami/utils/inflector.rb +0 -494
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8c15a181f268ff9117c181bfccc23c3fb63f31cbe38590f2d0b9f925e0fa9d1
|
4
|
+
data.tar.gz: bfdcc4baf599cd58adeb870ef700d705ec4cc58fdb58377f0028db177b3c431d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3099871c8e61b12217e0c9d5d2a5668daddcaf8d439190c2fb1a356a2b92d02859a1f258ba8b7517b3be8b3685664be1dd68676ecb7ae5f7f809e3a5371d1182
|
7
|
+
data.tar.gz: 3a7b06f9f9c7eda2f716f9e0fc77a9e4a97f5a5e6e6137b7dd6eb1e77b4f57a48249a364ea6a35712753582de244bc81e7978ac4c95bde7b2d8c86566a07c3c5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,47 @@
|
|
1
1
|
# Hanami::Utils
|
2
2
|
Ruby core extentions and class utilities for Hanami
|
3
3
|
|
4
|
+
## v2.0.0.alpha2 - 2021-05-04
|
5
|
+
### Changed
|
6
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.5.
|
7
|
+
- [Luca Guidi] Transform `Utils::String` from class to module
|
8
|
+
|
9
|
+
## v2.0.0.alpha1 - 2019-01-30
|
10
|
+
### Added
|
11
|
+
- [Gustavo Caso] Introduce `Hanami::Middleware` namespace
|
12
|
+
- [Luca Guidi] Introduce `Callbacks::Chain#dup`
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
|
16
|
+
- [Luca Guidi] Remove `Utils::Duplicable`
|
17
|
+
- [Luca Guidi] Remove `Utils::Inflector`
|
18
|
+
- [Luca Guidi] Remove `Utils::String.singularize`, and `.pluralize`
|
19
|
+
- [Luca Guidi] Remove `Utils::String#singularize`, and `#pluralize`
|
20
|
+
- [Luca Guidi] Remove instance level interface for `Utils::Hash`
|
21
|
+
- [Luca Guidi] Transform `Utils::Hash` from class to module
|
22
|
+
- [Luca Guidi] Remove `Utils.reload!`
|
23
|
+
- [Gustavo Caso] Remove `Utils::File.rewrite`
|
24
|
+
- [Vladimir Suvorov] Remove `Utils::Class.load_from_pattern!`
|
25
|
+
|
26
|
+
## v1.3.8 - 2021-05-03
|
27
|
+
### Fixed
|
28
|
+
- [Hiếu Nguyễn] Ensure `Hanami::Interactor#initialize` to accept keyword arguments while working with Ruby 3
|
29
|
+
|
30
|
+
## v1.3.7 - 2021-01-04
|
31
|
+
### Added
|
32
|
+
- [Luca Guidi] Official support for Ruby: MRI 3.0
|
33
|
+
- [Khai Le] Allow `Hanami::Logger` to filter sensitive data for an array of hashes
|
34
|
+
|
35
|
+
### Fixed
|
36
|
+
- [Hiếu Nguyễn] Ensure `Hanami::Logger` to not mutate `Hash` input when filtering sensitive data
|
37
|
+
|
38
|
+
## v1.3.6 - 2020-01-07
|
39
|
+
### Added
|
40
|
+
- [Luca Guidi] Official support for Ruby: MRI 2.7
|
41
|
+
|
42
|
+
### Fixed
|
43
|
+
- [ippachi] `Utils::Files.append`: don't check breakline if file is empty
|
44
|
+
|
4
45
|
## v1.3.5 - 2019-10-25
|
5
46
|
### Fixed
|
6
47
|
- [Ivan Kabluchkov] Ensure `Hanami::Logger` filters to not crash when logger stream is a closed tempfile
|
data/README.md
CHANGED
@@ -5,9 +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://codecov.io/gh/hanami/utils)
|
8
|
+
[](https://github.com/hanami/utils/actions?query=workflow%3Aci+branch%3Aunstable)
|
9
|
+
[](https://codecov.io/gh/hanami/utils)
|
11
10
|
[](https://depfu.com/github/hanami/utils?project=Bundler)
|
12
11
|
[](http://inch-ci.org/github/hanami/utils)
|
13
12
|
|
@@ -22,7 +21,7 @@ Ruby core extensions and class utilities for [Hanami](http://hanamirb.org)
|
|
22
21
|
|
23
22
|
## Rubies
|
24
23
|
|
25
|
-
__Hanami::Utils__ supports Ruby (MRI) 2.
|
24
|
+
__Hanami::Utils__ supports Ruby (MRI) 2.6+
|
26
25
|
|
27
26
|
## Installation
|
28
27
|
|
@@ -79,11 +78,6 @@ Inheritable class attributes. [[API doc](http://www.rubydoc.info/gems/hanami-uti
|
|
79
78
|
|
80
79
|
Deprecate Hanami features. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Deprecation)]
|
81
80
|
|
82
|
-
### Hanami::Utils::Duplicable
|
83
|
-
|
84
|
-
Safe `#dup` logic for Ruby objects. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Duplicable)]
|
85
|
-
|
86
|
-
|
87
81
|
### Hanami::Utils::Escape
|
88
82
|
|
89
83
|
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)]
|
@@ -98,16 +92,12 @@ File utilities to manipulate files and directories. [[API doc](http://www.rubydo
|
|
98
92
|
|
99
93
|
### Hanami::Utils::Hash
|
100
94
|
|
101
|
-
|
95
|
+
`Hash` transformations. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Hash)]
|
102
96
|
|
103
97
|
### Hanami::Utils::IO
|
104
98
|
|
105
99
|
Silence Ruby warnings. [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/IO)]
|
106
100
|
|
107
|
-
### Hanami::Utils::Inflector
|
108
|
-
|
109
|
-
Complete and customizable english inflections (pluralization and singularization). [[API doc](http://www.rubydoc.info/gems/hanami-utils/Hanami/Utils/Inflector)]
|
110
|
-
|
111
101
|
### Hanami::Utils::Json
|
112
102
|
|
113
103
|
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)]
|
@@ -150,6 +140,6 @@ __Hanami::Utils__ uses [Semantic Versioning 2.0.0](http://semver.org)
|
|
150
140
|
|
151
141
|
## Copyright
|
152
142
|
|
153
|
-
Copyright © 2014-
|
143
|
+
Copyright © 2014-2021 Luca Guidi – Released under MIT License
|
154
144
|
|
155
145
|
This project was formerly known as Lotus (`lotus-utils`).
|
data/hanami-utils.gemspec
CHANGED
@@ -1,27 +1,30 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require
|
5
|
+
require "hanami/utils/version"
|
4
6
|
|
5
7
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name =
|
8
|
+
spec.name = "hanami-utils"
|
7
9
|
spec.version = Hanami::Utils::VERSION
|
8
|
-
spec.authors = [
|
9
|
-
spec.email = [
|
10
|
-
spec.description =
|
11
|
-
spec.summary =
|
12
|
-
spec.homepage =
|
13
|
-
spec.license =
|
10
|
+
spec.authors = ["Luca Guidi"]
|
11
|
+
spec.email = ["me@lucaguidi.com"]
|
12
|
+
spec.description = "Hanami utilities"
|
13
|
+
spec.summary = "Ruby core extentions and Hanami utilities"
|
14
|
+
spec.homepage = "http://hanamirb.org"
|
15
|
+
spec.license = "MIT"
|
14
16
|
|
15
17
|
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-utils.gemspec`.split($/)
|
16
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
-
spec.require_paths = [
|
19
|
-
spec.required_ruby_version =
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
spec.required_ruby_version = ">= 2.6.0"
|
20
22
|
|
21
|
-
spec.add_dependency
|
22
|
-
spec.add_dependency
|
23
|
+
spec.add_dependency "dry-transformer", "~> 0.1"
|
24
|
+
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
23
25
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
26
|
+
spec.add_development_dependency "bundler", ">= 1.6", "< 3"
|
27
|
+
spec.add_development_dependency "rake", "~> 13"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.9"
|
29
|
+
spec.add_development_dependency "rubocop", "0.91"
|
27
30
|
end
|
data/lib/hanami-utils.rb
CHANGED
data/lib/hanami/interactor.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/utils/basic_object"
|
4
|
+
require "hanami/utils/class_attribute"
|
5
|
+
require "hanami/utils/hash"
|
4
6
|
|
5
7
|
module Hanami
|
6
8
|
# Hanami Interactor
|
@@ -17,14 +19,14 @@ module Hanami
|
|
17
19
|
# @api private
|
18
20
|
#
|
19
21
|
# @see Hanami::Interactor::Result#respond_to_missing?
|
20
|
-
METHODS = ::Hash[initialize:
|
21
|
-
success?:
|
22
|
+
METHODS = ::Hash[initialize: true,
|
23
|
+
success?: true,
|
22
24
|
successful?: true,
|
23
|
-
failure?:
|
24
|
-
fail!:
|
25
|
-
prepare!:
|
26
|
-
errors:
|
27
|
-
error:
|
25
|
+
failure?: true,
|
26
|
+
fail!: true,
|
27
|
+
prepare!: true,
|
28
|
+
errors: true,
|
29
|
+
error: true].freeze
|
28
30
|
|
29
31
|
# Initialize a new result
|
30
32
|
#
|
@@ -40,7 +42,7 @@ module Hanami
|
|
40
42
|
@success = true
|
41
43
|
end
|
42
44
|
|
43
|
-
#
|
45
|
+
# Checks if the current status is successful
|
44
46
|
#
|
45
47
|
# @return [TrueClass,FalseClass] the result of the check
|
46
48
|
#
|
@@ -50,9 +52,9 @@ module Hanami
|
|
50
52
|
end
|
51
53
|
|
52
54
|
# @since 0.3.5
|
53
|
-
|
55
|
+
alias_method :success?, :successful?
|
54
56
|
|
55
|
-
#
|
57
|
+
# Checks if the current status is not successful
|
56
58
|
#
|
57
59
|
# @return [TrueClass,FalseClass] the result of the check
|
58
60
|
#
|
@@ -61,7 +63,7 @@ module Hanami
|
|
61
63
|
!successful?
|
62
64
|
end
|
63
65
|
|
64
|
-
#
|
66
|
+
# Forces the status to be a failure
|
65
67
|
#
|
66
68
|
# @since 0.3.5
|
67
69
|
def fail!
|
@@ -104,7 +106,7 @@ module Hanami
|
|
104
106
|
errors.first
|
105
107
|
end
|
106
108
|
|
107
|
-
#
|
109
|
+
# Prepares the result before to be returned
|
108
110
|
#
|
109
111
|
# @param payload [Hash] an updated payload
|
110
112
|
#
|
@@ -179,10 +181,18 @@ module Hanami
|
|
179
181
|
# # ...
|
180
182
|
# end
|
181
183
|
# end
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
184
|
+
if RUBY_VERSION >= "3.0"
|
185
|
+
def initialize(*args, **kwargs)
|
186
|
+
super
|
187
|
+
ensure
|
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
|
186
196
|
end
|
187
197
|
|
188
198
|
# Triggers the operation and return a result.
|
@@ -351,33 +361,57 @@ module Hanami
|
|
351
361
|
# end
|
352
362
|
#
|
353
363
|
# Signup.new.call # => NoMethodError
|
354
|
-
|
355
|
-
|
356
|
-
|
364
|
+
if RUBY_VERSION >= "3.0"
|
365
|
+
def call(*args, **kwargs)
|
366
|
+
@__result = ::Hanami::Interactor::Result.new
|
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
|
357
374
|
end
|
358
375
|
|
359
376
|
private
|
360
377
|
|
361
378
|
# @api private
|
362
379
|
# @since 1.1.0
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
380
|
+
if RUBY_VERSION >= "3.0"
|
381
|
+
def _call(*args, **kwargs)
|
382
|
+
catch :fail do
|
383
|
+
validate!(*args, **kwargs)
|
384
|
+
yield
|
385
|
+
end
|
386
|
+
|
387
|
+
_prepare!
|
367
388
|
end
|
389
|
+
else
|
390
|
+
def _call(*args)
|
391
|
+
catch :fail do
|
392
|
+
validate!(*args)
|
393
|
+
yield
|
394
|
+
end
|
368
395
|
|
369
|
-
|
396
|
+
_prepare!
|
397
|
+
end
|
370
398
|
end
|
371
399
|
|
372
400
|
# @since 1.1.0
|
373
|
-
|
374
|
-
|
401
|
+
if RUBY_VERSION >= "3.0"
|
402
|
+
def validate!(*args, **kwargs)
|
403
|
+
fail! unless valid?(*args, **kwargs)
|
404
|
+
end
|
405
|
+
else
|
406
|
+
def validate!(*args)
|
407
|
+
fail! unless valid?(*args)
|
408
|
+
end
|
375
409
|
end
|
376
410
|
end
|
377
411
|
|
378
412
|
private
|
379
413
|
|
380
|
-
#
|
414
|
+
# Checks if proceed with <tt>#call</tt> invocation.
|
381
415
|
# By default it returns <tt>true</tt>.
|
382
416
|
#
|
383
417
|
# Developers can override it.
|
@@ -389,7 +423,7 @@ module Hanami
|
|
389
423
|
true
|
390
424
|
end
|
391
425
|
|
392
|
-
#
|
426
|
+
# Fails and interrupts the current flow.
|
393
427
|
#
|
394
428
|
# @since 0.3.5
|
395
429
|
#
|
@@ -428,7 +462,7 @@ module Hanami
|
|
428
462
|
throw :fail
|
429
463
|
end
|
430
464
|
|
431
|
-
#
|
465
|
+
# Logs an error without interrupting the flow.
|
432
466
|
#
|
433
467
|
# When used, the returned result won't be successful.
|
434
468
|
#
|
@@ -483,7 +517,7 @@ module Hanami
|
|
483
517
|
false
|
484
518
|
end
|
485
519
|
|
486
|
-
#
|
520
|
+
# Logs an error and interrupts the flow.
|
487
521
|
#
|
488
522
|
# When used, the returned result won't be successful.
|
489
523
|
#
|
@@ -546,7 +580,7 @@ module Hanami
|
|
546
580
|
# @since 0.5.0
|
547
581
|
# @api private
|
548
582
|
def _exposures
|
549
|
-
Hash[].tap do |result|
|
583
|
+
::Hash[].tap do |result|
|
550
584
|
self.class.exposures.each do |name, ivar|
|
551
585
|
result[name] = instance_variable_defined?(ivar) ? instance_variable_get(ivar) : nil
|
552
586
|
end
|
@@ -579,7 +613,7 @@ module Hanami
|
|
579
613
|
end
|
580
614
|
end
|
581
615
|
|
582
|
-
#
|
616
|
+
# Exposes local instance variables into the returning value of <tt>#call</tt>
|
583
617
|
#
|
584
618
|
# @param instance_variable_names [Symbol,Array<Symbol>] one or more instance
|
585
619
|
# variable names
|
@@ -588,7 +622,7 @@ module Hanami
|
|
588
622
|
#
|
589
623
|
# @see Hanami::Interactor::Result
|
590
624
|
#
|
591
|
-
# @example
|
625
|
+
# @example Exposes instance variable
|
592
626
|
#
|
593
627
|
# class Signup
|
594
628
|
# 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
|
@@ -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/SuppressedException
|
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) # rubocop:disable Layout/LineLength
|
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/SuppressedException
|
300
300
|
|
301
301
|
# Returns the current application name, this is used for tagging purposes
|
302
302
|
#
|
@@ -313,11 +313,11 @@ 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
|
320
|
-
super unless [STDOUT, $stdout].include?(@stream)
|
320
|
+
super unless [STDOUT, $stdout].include?(@stream) # rubocop:disable Style/GlobalStdStream
|
321
321
|
end
|
322
322
|
|
323
323
|
private
|