amazing-activist 0.5.2 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fab0193cbbc4c13ab7e7f2162143de36d01369aa84090020c4903164c9be3eb
4
- data.tar.gz: ce39998e2d99ab98dcd504b52f634ce0ad829fa0063ddb646a64627a21348f92
3
+ metadata.gz: bc682de44572c16ca1a0d4b1ad94e771c94a18f29ff7aafc53c2c6a44f5f9bdf
4
+ data.tar.gz: 9e5419f79392609bebf059df7380139262927b94e32b49df4c0770cadf437358
5
5
  SHA512:
6
- metadata.gz: d0c769b8a3b3ddfc1c1595c05c3b1093db5679c5a8f2ca2ef6076402113cb390b62ac4617b29e447426be8602f6df6825427b0e70d05e2c980747ddc98977b0a
7
- data.tar.gz: bc41b347b777da6516b4b1fbc08006816f953d79219f47df93a4e8530e3de60383f7441045c42ab7b300f17d3d8d9bc20902f59ca4222c11499573551933f199
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
@@ -62,6 +62,7 @@ This library aims to support and is tested against:
62
62
  ** MRI 3.1.x
63
63
  ** MRI 3.2.x
64
64
  ** MRI 3.3.x
65
+ ** MRI 3.4.x
65
66
 
66
67
  If something doesn't work on one of these versions, it's a bug.
67
68
 
@@ -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 [Hash]
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
- # @yieldparam self [self]
60
- def value_or
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
- # @return [Object]
39
- def value_or
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
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AmazingActivist
4
+ UNDEFINED = Object.new.freeze
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AmazingActivist
4
- VERSION = "0.5.2"
4
+ VERSION = "0.6.0"
5
5
  end
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.5.2
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-08-29 00:00:00.000000000 Z
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.5.2
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.5.2/CHANGES.md
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.5.11
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: []