amazing-activist 0.1.0 → 0.2.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/CHANGELOG.md +25 -0
- data/README.adoc +9 -0
- data/lib/amazing_activist/{activity.rb → base.rb} +2 -2
- data/lib/amazing_activist/locale/en.yml +4 -0
- data/lib/amazing_activist/locale/gl.yml +4 -0
- data/lib/amazing_activist/outcome/failure.rb +2 -1
- data/lib/amazing_activist/polyglot.rb +54 -0
- data/lib/amazing_activist/version.rb +1 -1
- data/lib/amazing_activist.rb +1 -1
- metadata +39 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f315ef7e7d9f2042299846f98243c0ba5b316cf5421d3c8f6d01f3340ed49b91
|
4
|
+
data.tar.gz: ec30a1a3f6f72d3c0daa5160af6e388b3a1f1d4a1110922c3730bf3ddc3da6d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d1a627bdd3555b90c232198db69b73da0cb6e3f51d6c4295e668ddb571fcce94bbe8d1f16d399622a5704cd2cf9c0e7e6e3a83d61bb7c5fa4595b85256f3153
|
7
|
+
data.tar.gz: de4a7d7cb65e4ab08d1c80b23fae22b11a86b225e578e07a03bd7e18bf78202d7a5c5a6bdae0436d5d77f1726464f99a564701d9734fef1dd02842d19ae2c8d2
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
|
11
|
+
## [0.2.0] - 2024-01-28
|
12
|
+
|
13
|
+
## Added
|
14
|
+
|
15
|
+
- Generate default failure messages with
|
16
|
+
[i18n](https://github.com/ruby-i18n/i18n).
|
17
|
+
|
18
|
+
|
19
|
+
## [0.1.0] - 2024-01-27
|
20
|
+
|
21
|
+
## Added
|
22
|
+
|
23
|
+
- Initial release.
|
24
|
+
|
25
|
+
[0.1.0]: https://github.com/ixti/sidekiq-antidote/tree/v0.1.0
|
data/README.adoc
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
= AmazingActivist
|
2
|
+
:ci-url: https://github.com/ixti/amazing-activist/actions/workflows/ci.yml?query=branch%3Amain
|
3
|
+
:ci-img: https://github.com/ixti/amazing-activist/actions/workflows/ci.yml/badge.svg?branch=main
|
4
|
+
:codecov-url: https://codecov.io/gh/ixti/amazing-activist/tree/main
|
5
|
+
:codecov-img: https://codecov.io/gh/ixti/amazing-activist/graph/badge.svg?token=LXaGWwv5xl
|
6
|
+
|
7
|
+
ifdef::env-github[]
|
8
|
+
{ci-url}[image:{ci-img}[CI]]
|
9
|
+
{codecov-url}[image:{codecov-img}[codecov]]
|
10
|
+
endif::[]
|
2
11
|
|
3
12
|
== Installation
|
4
13
|
|
@@ -9,7 +9,7 @@ module AmazingActivist
|
|
9
9
|
#
|
10
10
|
# [source,ruby]
|
11
11
|
# ----
|
12
|
-
# class OnboardActivity < AmazingActivist::
|
12
|
+
# class OnboardActivity < AmazingActivist::Base
|
13
13
|
# def call
|
14
14
|
# user = User.new(params)
|
15
15
|
#
|
@@ -19,7 +19,7 @@ module AmazingActivist
|
|
19
19
|
# end
|
20
20
|
# end
|
21
21
|
# ----
|
22
|
-
class
|
22
|
+
class Base
|
23
23
|
class << self
|
24
24
|
# Convenience method to initialize and immediatelly call the activity.
|
25
25
|
# @see #initialize
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative "../polyglot"
|
3
4
|
require_relative "../unwrap_error"
|
4
5
|
|
5
6
|
module AmazingActivist
|
@@ -56,7 +57,7 @@ module AmazingActivist
|
|
56
57
|
end
|
57
58
|
|
58
59
|
def message
|
59
|
-
|
60
|
+
@context.fetch(:message) { Polyglot.new(@activity).message(@code, **context) }
|
60
61
|
end
|
61
62
|
end
|
62
63
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
require "active_support/core_ext/string/inflections"
|
5
|
+
|
6
|
+
require "i18n"
|
7
|
+
|
8
|
+
I18n.load_path += Dir[File.expand_path("#{__dir__}/locale/*.yml")]
|
9
|
+
|
10
|
+
module AmazingActivist
|
11
|
+
# @api internal
|
12
|
+
class Polyglot
|
13
|
+
ANONYMOUS_ACTIVITY_NAME = "anonymous"
|
14
|
+
private_constant :ANONYMOUS_ACTIVITY_NAME
|
15
|
+
|
16
|
+
def initialize(activity)
|
17
|
+
@activity = activity
|
18
|
+
end
|
19
|
+
|
20
|
+
# The i18n key for the message will be looked in namespaces:
|
21
|
+
#
|
22
|
+
# * `amazing_activist.activities.[activity].failures`
|
23
|
+
# * `amazing_activist.failures`
|
24
|
+
#
|
25
|
+
# Thus, if activity `Pretty::DamnGoodActivity` failed with `:bad_choise`
|
26
|
+
# code the lookup will be:
|
27
|
+
#
|
28
|
+
# * `amazing_activist.activities.pretty/damn_good.failures.bad_choice
|
29
|
+
# * `amazing_activist.failures.bad_choice
|
30
|
+
#
|
31
|
+
# If there's no translation with any of the above keys, a generic
|
32
|
+
# non-translated message will be used:
|
33
|
+
#
|
34
|
+
# <pretty/damn_good> activity failed - bad_choice
|
35
|
+
#
|
36
|
+
# @return [String] Failure message
|
37
|
+
def message(code, **context)
|
38
|
+
default = [
|
39
|
+
:"amazing_activist.failures.#{code}",
|
40
|
+
"<%{activity}> activity failed - %{code}" # rubocop:disable Style/FormatStringToken
|
41
|
+
]
|
42
|
+
|
43
|
+
if @activity.class.name
|
44
|
+
activity = @activity.class.name.underscore.presence.delete_suffix("_activity")
|
45
|
+
i18n_key = :"amazing_activist.activities.#{activity}.failures.#{code}"
|
46
|
+
else
|
47
|
+
activity = "(anonymous)"
|
48
|
+
i18n_key = default.shift
|
49
|
+
end
|
50
|
+
|
51
|
+
I18n.t(i18n_key, **context, default: default, activity: activity, code: code)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/amazing_activist.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: amazing-activist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
12
|
-
dependencies:
|
11
|
+
date: 2024-01-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: i18n
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Another take on Command Pattern.
|
14
42
|
email:
|
15
43
|
- alexey@zapparov.com
|
@@ -17,15 +45,19 @@ executables: []
|
|
17
45
|
extensions: []
|
18
46
|
extra_rdoc_files: []
|
19
47
|
files:
|
48
|
+
- CHANGELOG.md
|
20
49
|
- LICENSE.txt
|
21
50
|
- README.adoc
|
22
51
|
- lib/amazing-activist.rb
|
23
52
|
- lib/amazing_activist.rb
|
24
|
-
- lib/amazing_activist/
|
53
|
+
- lib/amazing_activist/base.rb
|
25
54
|
- lib/amazing_activist/error.rb
|
55
|
+
- lib/amazing_activist/locale/en.yml
|
56
|
+
- lib/amazing_activist/locale/gl.yml
|
26
57
|
- lib/amazing_activist/outcome.rb
|
27
58
|
- lib/amazing_activist/outcome/failure.rb
|
28
59
|
- lib/amazing_activist/outcome/success.rb
|
60
|
+
- lib/amazing_activist/polyglot.rb
|
29
61
|
- lib/amazing_activist/unwrap_error.rb
|
30
62
|
- lib/amazing_activist/version.rb
|
31
63
|
homepage: https://github.com/ixti/amazing-activist
|
@@ -33,9 +65,9 @@ licenses:
|
|
33
65
|
- MIT
|
34
66
|
metadata:
|
35
67
|
homepage_uri: https://github.com/ixti/amazing-activist
|
36
|
-
source_code_uri: https://github.com/ixti/amazing-activist/tree/v0.
|
68
|
+
source_code_uri: https://github.com/ixti/amazing-activist/tree/v0.2.0
|
37
69
|
bug_tracker_uri: https://github.com/ixti/amazing-activist/issues
|
38
|
-
changelog_uri: https://github.com/ixti/amazing-activist/blob/v0.
|
70
|
+
changelog_uri: https://github.com/ixti/amazing-activist/blob/v0.2.0/CHANGES.md
|
39
71
|
rubygems_mfa_required: 'true'
|
40
72
|
post_install_message:
|
41
73
|
rdoc_options: []
|
@@ -52,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
84
|
- !ruby/object:Gem::Version
|
53
85
|
version: '0'
|
54
86
|
requirements: []
|
55
|
-
rubygems_version: 3.
|
87
|
+
rubygems_version: 3.2.33
|
56
88
|
signing_key:
|
57
89
|
specification_version: 4
|
58
90
|
summary: Your friendly neighborhood activist.
|