amazing-activist 0.5.2 → 0.7.0
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/CHANGES.md +31 -0
- data/README.adoc +1 -2
- data/lib/amazing_activist/base.rb +1 -7
- data/lib/amazing_activist/contractable.rb +8 -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 +21 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 541998aec21a78778cf6cbe4ed8abfe84f86873c43e42edc965b4a78c97288e0
|
4
|
+
data.tar.gz: 9aa931fd204447211f02848d4e288a9edab389f3c65e3c3a4725fa7ada14b0a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4d7b6fff7d8191b23b4cd4dc924939af064a3bd92cda61fbdc4f7e3fed5a06a1d13f05834352e469b0dddf603819d0cdbf74b10deba539df71f8226dd5d7437
|
7
|
+
data.tar.gz: c342b3f260a7e66a395a13f5c01b60fcdde87c94fb00745ccaf426271e6ff4afdf0bf243133229bb21ab2862a178801f670da4ff768ae0b8f267e88f6e509375
|
data/CHANGES.md
CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
|
11
|
+
## [0.7.0] - 2025-04-14
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- Use [literal](https://github.com/joeldrapper/literal) gem to aid inputs
|
16
|
+
boilerplate.
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- (BREAKING) Drop support of Ruby-3.0.X, and Ruby-3.1.X
|
21
|
+
|
22
|
+
|
23
|
+
## [0.6.0] - 2024-12-15
|
24
|
+
|
25
|
+
### Added
|
26
|
+
|
27
|
+
- Support Ruby-3.4.X.
|
28
|
+
- Add `Success#inspect` and `Failure#inspect` methods.
|
29
|
+
- Support default value literal in `Failure#value_or`.
|
30
|
+
|
31
|
+
### Changed
|
32
|
+
|
33
|
+
- (BREAKING) `Success#value_or` requries default value or block to keep it
|
34
|
+
consistent with `Failure#value_or`.
|
35
|
+
|
36
|
+
|
10
37
|
## [0.5.2] - 2024-08-30
|
11
38
|
|
12
39
|
### Changed
|
@@ -70,6 +97,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
70
97
|
|
71
98
|
- Initial release.
|
72
99
|
|
100
|
+
[Unreleased]: https://github.com/ixti/amazing-activist/compare/v0.7.0...main
|
101
|
+
[0.7.0]: https://github.com/ixti/amazing-activist/compare/v0.6.0...v0.7.0
|
102
|
+
[0.6.0]: https://github.com/ixti/amazing-activist/compare/v0.5.2...v0.6.0
|
103
|
+
[0.5.2]: https://github.com/ixti/amazing-activist/compare/v0.5.1...v0.5.2
|
73
104
|
[0.5.1]: https://github.com/ixti/amazing-activist/compare/v0.5.0...v0.5.1
|
74
105
|
[0.5.0]: https://github.com/ixti/amazing-activist/compare/v0.4.0...v0.5.0
|
75
106
|
[0.4.0]: https://github.com/ixti/amazing-activist/compare/v0.3.0...v0.4.0
|
data/README.adoc
CHANGED
@@ -58,10 +58,9 @@ end
|
|
58
58
|
This library aims to support and is tested against:
|
59
59
|
|
60
60
|
* https://www.ruby-lang.org[Ruby]
|
61
|
-
** MRI 3.0.x
|
62
|
-
** MRI 3.1.x
|
63
61
|
** MRI 3.2.x
|
64
62
|
** MRI 3.3.x
|
63
|
+
** MRI 3.4.x
|
65
64
|
|
66
65
|
If something doesn't work on one of these versions, it's a bug.
|
67
66
|
|
@@ -31,10 +31,7 @@ module AmazingActivist
|
|
31
31
|
class Base
|
32
32
|
extend Irresistible
|
33
33
|
|
34
|
-
|
35
|
-
def initialize(**params)
|
36
|
-
@params = params
|
37
|
-
end
|
34
|
+
prop :params, _Hash(Symbol, _Any?), :**
|
38
35
|
|
39
36
|
# @return [Outcome::Success, Outcome::Failure]
|
40
37
|
def call
|
@@ -43,9 +40,6 @@ module AmazingActivist
|
|
43
40
|
|
44
41
|
private
|
45
42
|
|
46
|
-
# @return [Hash{Symbol => Object}]
|
47
|
-
attr_reader :params
|
48
|
-
|
49
43
|
# @param value (see Outcome::Success#initialize)
|
50
44
|
# @return [Outcome::Success]
|
51
45
|
def success(value = nil)
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "literal"
|
4
|
+
|
3
5
|
require_relative "./broken_contract_error"
|
4
6
|
|
5
7
|
module AmazingActivist
|
6
8
|
module Contractable
|
9
|
+
include Literal::Properties
|
10
|
+
|
7
11
|
DEFAULT_BROKEN_OUTCOME_HANDLER = lambda do |outcome|
|
8
12
|
raise BrokenContractError, "#{self.class}#call returned #{outcome.class} instead of Outcome"
|
9
13
|
end
|
@@ -26,6 +30,10 @@ module AmazingActivist
|
|
26
30
|
|
27
31
|
private
|
28
32
|
|
33
|
+
def prop(name, type, kind = :keyword, reader: :private, default: nil, &)
|
34
|
+
super(name, type, kind, reader:, writer: false, predicate: false, default:, &)
|
35
|
+
end
|
36
|
+
|
29
37
|
def on_broken_outcome(&block)
|
30
38
|
raise ArgumentError, "Handler block required." unless block
|
31
39
|
|
@@ -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,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazing-activist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -38,6 +37,20 @@ dependencies:
|
|
38
37
|
- - ">="
|
39
38
|
- !ruby/object:Gem::Version
|
40
39
|
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: literal
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
41
54
|
description: Another take on Command Pattern.
|
42
55
|
email:
|
43
56
|
- alexey@zapparov.com
|
@@ -62,6 +75,7 @@ files:
|
|
62
75
|
- lib/amazing_activist/outcome/success.rb
|
63
76
|
- lib/amazing_activist/polyglot.rb
|
64
77
|
- lib/amazing_activist/rescuable.rb
|
78
|
+
- lib/amazing_activist/undefined.rb
|
65
79
|
- lib/amazing_activist/unwrap_error.rb
|
66
80
|
- lib/amazing_activist/version.rb
|
67
81
|
homepage: https://github.com/ixti/amazing-activist
|
@@ -69,11 +83,10 @@ licenses:
|
|
69
83
|
- MIT
|
70
84
|
metadata:
|
71
85
|
homepage_uri: https://github.com/ixti/amazing-activist
|
72
|
-
source_code_uri: https://github.com/ixti/amazing-activist/tree/v0.
|
86
|
+
source_code_uri: https://github.com/ixti/amazing-activist/tree/v0.7.0
|
73
87
|
bug_tracker_uri: https://github.com/ixti/amazing-activist/issues
|
74
|
-
changelog_uri: https://github.com/ixti/amazing-activist/blob/v0.
|
88
|
+
changelog_uri: https://github.com/ixti/amazing-activist/blob/v0.7.0/CHANGES.md
|
75
89
|
rubygems_mfa_required: 'true'
|
76
|
-
post_install_message:
|
77
90
|
rdoc_options: []
|
78
91
|
require_paths:
|
79
92
|
- lib
|
@@ -81,15 +94,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
94
|
requirements:
|
82
95
|
- - ">="
|
83
96
|
- !ruby/object:Gem::Version
|
84
|
-
version: 3.
|
97
|
+
version: 3.2.0
|
85
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
99
|
requirements:
|
87
100
|
- - ">="
|
88
101
|
- !ruby/object:Gem::Version
|
89
102
|
version: '0'
|
90
103
|
requirements: []
|
91
|
-
rubygems_version: 3.5
|
92
|
-
signing_key:
|
104
|
+
rubygems_version: 3.6.5
|
93
105
|
specification_version: 4
|
94
106
|
summary: Your friendly neighborhood activist.
|
95
107
|
test_files: []
|