amazing-activist 0.5.1 → 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: e1b67a3e5f375db018b80c5576790c70199cab89e8e352bf2700f06e2efa8678
4
- data.tar.gz: 313e959d99e39ec6c6c759748bdd08889c73945388ed5240e5919043968558f5
3
+ metadata.gz: bc682de44572c16ca1a0d4b1ad94e771c94a18f29ff7aafc53c2c6a44f5f9bdf
4
+ data.tar.gz: 9e5419f79392609bebf059df7380139262927b94e32b49df4c0770cadf437358
5
5
  SHA512:
6
- metadata.gz: 2f97922ccb1e84836578e2103f17b34e6a0081d29f6370aac8438b9cfdbf53974c3d14ab66f92f56569ca2481c0000e069db0967be80614578d7edf8881f7bfa
7
- data.tar.gz: a53cc57eb23851df4af94092f83506fc23d79769158d8ac7105badd94742d68e08959add4746eb41f767bb1fd2b0fec082ee161caf73722a200420a96cd68a72
6
+ metadata.gz: 93ace31de12aecf905e25390b51e4672c46a3cd5dfb8bf5bf38f70c04bfd0dd16e03bdb0fb192fc52f889b679810e9b2312a5b8a859148b809d54aca9954c218
7
+ data.tar.gz: 4681c868840de2df1030f11da788247763f5fd92ea69da706d62b3bcb7b2e1f0e6d455eaf288d3b16a26c9b9d6941b9a0cc538cc2c8e814a8ca805d48582d956
data/CHANGES.md CHANGED
@@ -8,7 +8,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [Unreleased]
9
9
 
10
10
 
11
- ## [0.5.1] - 2023-04-26
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
+
25
+ ## [0.5.2] - 2024-08-30
26
+
27
+ ### Changed
28
+
29
+ - i18n now looks for keys without `amazing_activist` prefix as well; Lookup
30
+ order now goes like: `amazing_activist.activities.[activity].failures`,
31
+ `activities.[activity].failures`, `amazing_activist.failures`,
32
+ `activities.failures`, with fallback to hardcoded `"<[activity]> failed - [code]"`.
33
+
34
+
35
+ ## [0.5.1] - 2024-04-26
12
36
 
13
37
  ### Changed
14
38
 
@@ -16,7 +40,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
16
40
  keys are present and do not include it.
17
41
 
18
42
 
19
- ## [0.5.0] - 2023-03-13
43
+ ## [0.5.0] - 2024-03-13
20
44
 
21
45
  ### Changed
22
46
 
@@ -61,6 +85,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
61
85
 
62
86
  - Initial release.
63
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
64
91
  [0.5.1]: https://github.com/ixti/amazing-activist/compare/v0.5.0...v0.5.1
65
92
  [0.5.0]: https://github.com/ixti/amazing-activist/compare/v0.4.0...v0.5.0
66
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
 
@@ -17,13 +17,17 @@ module AmazingActivist
17
17
  # The i18n key for the message will be looked in namespaces:
18
18
  #
19
19
  # * `amazing_activist.activities.[activity].failures`
20
+ # * `activities.[activity].failures`
20
21
  # * `amazing_activist.failures`
22
+ # * `activities.failures`
21
23
  #
22
24
  # Thus, if activity `Pretty::DamnGoodActivity` failed with `:bad_choise`
23
25
  # code the lookup will be:
24
26
  #
25
27
  # * `amazing_activist.activities.pretty/damn_good_activity.failures.bad_choice
28
+ # * `activities.pretty/damn_good_activity.failures.bad_choice
26
29
  # * `amazing_activist.failures.bad_choice
30
+ # * `activities.failures.bad_choice
27
31
  #
28
32
  # If there's no translation with any of the above keys, a generic
29
33
  # non-translated message will be used:
@@ -32,14 +36,16 @@ module AmazingActivist
32
36
  #
33
37
  # @return [String] Failure message
34
38
  def message(code, **context)
35
- default = [
39
+ activity = @activity.class.name&.underscore
40
+ default = [
36
41
  :"amazing_activist.failures.#{code}",
42
+ :"activities.failures.#{code}",
37
43
  "<%{activity}> failed - %{code}" # rubocop:disable Style/FormatStringToken
38
44
  ]
39
45
 
40
- if @activity.class.name
41
- activity = @activity.class.name.underscore.presence
46
+ if activity
42
47
  i18n_key = :"amazing_activist.activities.#{activity}.failures.#{code}"
48
+ default.unshift(:"activities.#{activity}.failures.#{code}")
43
49
  else
44
50
  activity = "(anonymous activity)"
45
51
  i18n_key = default.shift
@@ -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.1"
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.1
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-04-26 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.1
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.1/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.4
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: []