amazing-activist 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a8cba9d28e25f87ba33a43233f981a13826c716db8342fa1df5a39ed14ca59c1
4
- data.tar.gz: bcda1343f32f2df0aec0e3aaa806f602b98410e9a54d4a79214859f21830d275
3
+ metadata.gz: f315ef7e7d9f2042299846f98243c0ba5b316cf5421d3c8f6d01f3340ed49b91
4
+ data.tar.gz: ec30a1a3f6f72d3c0daa5160af6e388b3a1f1d4a1110922c3730bf3ddc3da6d1
5
5
  SHA512:
6
- metadata.gz: c57c413901c0323f40a153d42a4b22be48281a1f6e76ceb2065cc94aed379a3d69238dfddde3537fa3ded78e573c3c9a168fcd76eb1c2547ed228b3b622f47cd
7
- data.tar.gz: 9d37d65dc06c8a8784b4bc9ea4d6c1c2d72798cfea742e292e8a4d0847451dc851024a0fef330889d27d56313d944107354dc0a7dd300aed01859bc1d67383b9
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::Activity
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 Activity
22
+ class Base
23
23
  class << self
24
24
  # Convenience method to initialize and immediatelly call the activity.
25
25
  # @see #initialize
@@ -0,0 +1,4 @@
1
+ en:
2
+ amazing_activist:
3
+ failures:
4
+ not_implemented: "<%{activity}> activity has no implementation"
@@ -0,0 +1,4 @@
1
+ gl:
2
+ amazing_activist:
3
+ failures:
4
+ not_implemented: "<%{activity}> actividade non ten implementación"
@@ -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
- "#{@activity.class} failed with #{@code}"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module AmazingActivist
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "./amazing_activist/activity"
3
+ require_relative "./amazing_activist/base"
4
4
  require_relative "./amazing_activist/error"
5
5
  require_relative "./amazing_activist/outcome"
6
6
  require_relative "./amazing_activist/version"
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.1.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-27 00:00:00.000000000 Z
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/activity.rb
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.1.0
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.1.0/CHANGES.md
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.5.4
87
+ rubygems_version: 3.2.33
56
88
  signing_key:
57
89
  specification_version: 4
58
90
  summary: Your friendly neighborhood activist.