amazing-activist 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +18 -0
- data/README.adoc +1 -0
- data/lib/amazing_activist/outcome/failure.rb +25 -4
- data/lib/amazing_activist/outcome/success.rb +23 -2
- data/lib/amazing_activist/undefined.rb +5 -0
- data/lib/amazing_activist/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc682de44572c16ca1a0d4b1ad94e771c94a18f29ff7aafc53c2c6a44f5f9bdf
|
4
|
+
data.tar.gz: 9e5419f79392609bebf059df7380139262927b94e32b49df4c0770cadf437358
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93ace31de12aecf905e25390b51e4672c46a3cd5dfb8bf5bf38f70c04bfd0dd16e03bdb0fb192fc52f889b679810e9b2312a5b8a859148b809d54aca9954c218
|
7
|
+
data.tar.gz: 4681c868840de2df1030f11da788247763f5fd92ea69da706d62b3bcb7b2e1f0e6d455eaf288d3b16a26c9b9d6941b9a0cc538cc2c8e814a8ca805d48582d956
|
data/CHANGES.md
CHANGED
@@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
|
11
|
+
## [0.6.0] - 2024-12-15
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Support Ruby-3.4.X.
|
16
|
+
- Add `Success#inspect` and `Failure#inspect` methods.
|
17
|
+
- Support default value literal in `Failure#value_or`.
|
18
|
+
|
19
|
+
### Changed
|
20
|
+
|
21
|
+
- (BREAKING) `Success#value_or` requries default value or block to keep it
|
22
|
+
consistent with `Failure#value_or`.
|
23
|
+
|
24
|
+
|
10
25
|
## [0.5.2] - 2024-08-30
|
11
26
|
|
12
27
|
### Changed
|
@@ -70,6 +85,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
70
85
|
|
71
86
|
- Initial release.
|
72
87
|
|
88
|
+
[Unreleased]: https://github.com/ixti/amazing-activist/compare/v0.6.0...main
|
89
|
+
[0.6.0]: https://github.com/ixti/amazing-activist/compare/v0.5.2...v0.6.0
|
90
|
+
[0.5.2]: https://github.com/ixti/amazing-activist/compare/v0.5.1...v0.5.2
|
73
91
|
[0.5.1]: https://github.com/ixti/amazing-activist/compare/v0.5.0...v0.5.1
|
74
92
|
[0.5.0]: https://github.com/ixti/amazing-activist/compare/v0.4.0...v0.5.0
|
75
93
|
[0.4.0]: https://github.com/ixti/amazing-activist/compare/v0.3.0...v0.4.0
|
data/README.adoc
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative "../polyglot"
|
4
4
|
require_relative "../unwrap_error"
|
5
|
+
require_relative "../undefined"
|
5
6
|
|
6
7
|
module AmazingActivist
|
7
8
|
module Outcome
|
@@ -22,15 +23,21 @@ module AmazingActivist
|
|
22
23
|
# @param activity [AmazingActivist::Activity]
|
23
24
|
# @param message [#to_s, nil]
|
24
25
|
# @param exception [Exception, nil]
|
25
|
-
# @param context [
|
26
|
+
# @param context [#to_h]
|
26
27
|
def initialize(code, activity:, message:, exception:, context:)
|
27
28
|
@code = code.to_sym
|
28
29
|
@activity = activity
|
29
30
|
@message = message&.to_s
|
30
31
|
@exception = exception
|
31
|
-
@context = context
|
32
|
+
@context = context.to_h
|
32
33
|
end
|
33
34
|
|
35
|
+
def inspect
|
36
|
+
"#<#{self.class} (#{@activity.class}) #{@code.inspect}>"
|
37
|
+
end
|
38
|
+
|
39
|
+
alias to_s inspect
|
40
|
+
|
34
41
|
# @return [true]
|
35
42
|
def success?
|
36
43
|
false
|
@@ -56,8 +63,22 @@ module AmazingActivist
|
|
56
63
|
deconstructed
|
57
64
|
end
|
58
65
|
|
59
|
-
# @
|
60
|
-
|
66
|
+
# @overload value_or(default)
|
67
|
+
# @param default [Object]
|
68
|
+
# @return [Object] default value
|
69
|
+
# @overload value_or(&block)
|
70
|
+
# @yieldparam self [self]
|
71
|
+
# @yieldreturn [Object] result of the block
|
72
|
+
# @raise [ArgumentError] if neither default value, nor block given
|
73
|
+
def value_or(default = UNDEFINED)
|
74
|
+
raise ArgumentError, "either default value, or block must be given" if default == UNDEFINED && !block_given?
|
75
|
+
|
76
|
+
unless default == UNDEFINED
|
77
|
+
return default unless block_given?
|
78
|
+
|
79
|
+
warn "block supersedes default value argument"
|
80
|
+
end
|
81
|
+
|
61
82
|
yield self
|
62
83
|
end
|
63
84
|
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../undefined"
|
4
|
+
|
3
5
|
module AmazingActivist
|
4
6
|
module Outcome
|
5
7
|
class Success
|
@@ -13,6 +15,12 @@ module AmazingActivist
|
|
13
15
|
@activity = activity
|
14
16
|
end
|
15
17
|
|
18
|
+
def inspect
|
19
|
+
"#<#{self.class} (#{@activity.class}) #{@value.inspect}>"
|
20
|
+
end
|
21
|
+
|
22
|
+
alias to_s inspect
|
23
|
+
|
16
24
|
# @return [true]
|
17
25
|
def success?
|
18
26
|
true
|
@@ -35,8 +43,21 @@ module AmazingActivist
|
|
35
43
|
{ success: @value, activity: @activity }
|
36
44
|
end
|
37
45
|
|
38
|
-
# @
|
39
|
-
|
46
|
+
# @note Method requires default value or block (even though neither will
|
47
|
+
# be used) to keep it consistent with {Failure#value_or}, and avoid
|
48
|
+
# unpleasant surprises when code is not testing all possible outcomes.
|
49
|
+
#
|
50
|
+
# @raise [ArgumentError] if neither default value, nor block given
|
51
|
+
# @return [Object] unwrapped value
|
52
|
+
def value_or(default = UNDEFINED)
|
53
|
+
raise ArgumentError, "either default value, or block must be given" if default == UNDEFINED && !block_given?
|
54
|
+
|
55
|
+
unless default == UNDEFINED
|
56
|
+
return @value unless block_given?
|
57
|
+
|
58
|
+
warn "block supersedes default value argument"
|
59
|
+
end
|
60
|
+
|
40
61
|
@value
|
41
62
|
end
|
42
63
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazing-activist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
|
+
original_platform: ''
|
6
7
|
authors:
|
7
8
|
- Alexey Zapparov
|
8
|
-
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/amazing_activist/outcome/success.rb
|
63
63
|
- lib/amazing_activist/polyglot.rb
|
64
64
|
- lib/amazing_activist/rescuable.rb
|
65
|
+
- lib/amazing_activist/undefined.rb
|
65
66
|
- lib/amazing_activist/unwrap_error.rb
|
66
67
|
- lib/amazing_activist/version.rb
|
67
68
|
homepage: https://github.com/ixti/amazing-activist
|
@@ -69,11 +70,10 @@ licenses:
|
|
69
70
|
- MIT
|
70
71
|
metadata:
|
71
72
|
homepage_uri: https://github.com/ixti/amazing-activist
|
72
|
-
source_code_uri: https://github.com/ixti/amazing-activist/tree/v0.
|
73
|
+
source_code_uri: https://github.com/ixti/amazing-activist/tree/v0.6.0
|
73
74
|
bug_tracker_uri: https://github.com/ixti/amazing-activist/issues
|
74
|
-
changelog_uri: https://github.com/ixti/amazing-activist/blob/v0.
|
75
|
+
changelog_uri: https://github.com/ixti/amazing-activist/blob/v0.6.0/CHANGES.md
|
75
76
|
rubygems_mfa_required: 'true'
|
76
|
-
post_install_message:
|
77
77
|
rdoc_options: []
|
78
78
|
require_paths:
|
79
79
|
- lib
|
@@ -88,8 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
requirements: []
|
91
|
-
rubygems_version: 3.
|
92
|
-
signing_key:
|
91
|
+
rubygems_version: 3.6.0.dev
|
93
92
|
specification_version: 4
|
94
93
|
summary: Your friendly neighborhood activist.
|
95
94
|
test_files: []
|