readymade 0.4.0 → 0.4.2
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 +9 -0
- data/Gemfile.lock +22 -18
- data/README.md +4 -1
- data/lib/.DS_Store +0 -0
- data/lib/readymade/action.rb +1 -1
- data/lib/readymade/background_bang_job.rb +1 -3
- data/lib/readymade/background_job.rb +30 -1
- data/lib/readymade/controller/serialization.rb +1 -1
- data/lib/readymade/model/validatable_enum.rb +32 -0
- data/lib/readymade/response.rb +14 -0
- data/lib/readymade/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9a882e1827fc02ccf9591bd9b553a3125400b613896043759e8d6b67583f1a6
|
4
|
+
data.tar.gz: 6cd288e19b31eaf1584da299a72b8ba80dd9bf5eb89f8f8adeac0b161d68ff7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18db5112a9b9d07f7a344fa9213cac219ffc99c82d6c74fa645839c9c3e25f1402c29d4d05aacf8baaafd2d67cde6d6e748708f73a486625b375ab32bad25db7
|
7
|
+
data.tar.gz: bca496b18a8a38f5d1298aa379f11a6ff713fcb59d44ad34a31a753b518569186734c08032f94be8c407dd75dfd4e9c3709cc7b73d82fb969912515cfc4813d5
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
Changelog
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
|
+
## [0.4.2] - 2025-05-26
|
5
|
+
|
6
|
+
* Add `job_options.discard_on` argument to `Readymade::BackgroundJob` to discard job on specific exceptions
|
7
|
+
* Deprecated `queue_as` argument in `Readymade::BackgroundJob` in favor of `job_options.queue_as`
|
8
|
+
|
9
|
+
## [0.4.1] - 2024-07-15
|
10
|
+
|
11
|
+
* Add `message` to `Reaymade::UnSuccessError` exception
|
12
|
+
|
4
13
|
## [0.4.0] - 2024-02-23
|
5
14
|
|
6
15
|
* Add `Reaymade::Model::ValidatableEnum` to validate enum values
|
data/Gemfile.lock
CHANGED
@@ -1,42 +1,45 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
readymade (0.4.
|
4
|
+
readymade (0.4.2)
|
5
5
|
activejob
|
6
6
|
activemodel
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activejob (
|
12
|
-
activesupport (=
|
11
|
+
activejob (8.0.2)
|
12
|
+
activesupport (= 8.0.2)
|
13
13
|
globalid (>= 0.3.6)
|
14
|
-
activemodel (
|
15
|
-
activesupport (=
|
16
|
-
activesupport (
|
14
|
+
activemodel (8.0.2)
|
15
|
+
activesupport (= 8.0.2)
|
16
|
+
activesupport (8.0.2)
|
17
17
|
base64
|
18
|
+
benchmark (>= 0.3)
|
18
19
|
bigdecimal
|
19
|
-
concurrent-ruby (~> 1.0, >= 1.
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
20
21
|
connection_pool (>= 2.2.5)
|
21
22
|
drb
|
22
23
|
i18n (>= 1.6, < 2)
|
24
|
+
logger (>= 1.4.2)
|
23
25
|
minitest (>= 5.1)
|
24
|
-
|
25
|
-
tzinfo (~> 2.0)
|
26
|
+
securerandom (>= 0.3)
|
27
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
28
|
+
uri (>= 0.13.1)
|
26
29
|
base64 (0.2.0)
|
27
|
-
|
30
|
+
benchmark (0.4.0)
|
31
|
+
bigdecimal (3.1.9)
|
28
32
|
byebug (11.1.3)
|
29
|
-
concurrent-ruby (1.
|
30
|
-
connection_pool (2.
|
33
|
+
concurrent-ruby (1.3.5)
|
34
|
+
connection_pool (2.5.3)
|
31
35
|
diff-lcs (1.4.4)
|
32
|
-
drb (2.2.
|
33
|
-
ruby2_keywords
|
36
|
+
drb (2.2.3)
|
34
37
|
globalid (1.2.1)
|
35
38
|
activesupport (>= 6.1)
|
36
|
-
i18n (1.14.
|
39
|
+
i18n (1.14.7)
|
37
40
|
concurrent-ruby (~> 1.0)
|
38
|
-
|
39
|
-
|
41
|
+
logger (1.7.0)
|
42
|
+
minitest (5.25.5)
|
40
43
|
rake (13.0.6)
|
41
44
|
rspec (3.10.0)
|
42
45
|
rspec-core (~> 3.10.0)
|
@@ -51,9 +54,10 @@ GEM
|
|
51
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
55
|
rspec-support (~> 3.10.0)
|
53
56
|
rspec-support (3.10.3)
|
54
|
-
|
57
|
+
securerandom (0.4.1)
|
55
58
|
tzinfo (2.0.6)
|
56
59
|
concurrent-ruby (~> 1.0)
|
60
|
+
uri (1.0.3)
|
57
61
|
|
58
62
|
PLATFORMS
|
59
63
|
ruby
|
data/README.md
CHANGED
@@ -146,7 +146,10 @@ class Orders::Actions::SendNotifications < Readymade::Action
|
|
146
146
|
end
|
147
147
|
|
148
148
|
Orders::Actions::SendNotifications.call_async(order: order)
|
149
|
-
Orders::Actions::SendNotifications.call_async!(order: order, queue_as: :my_queue
|
149
|
+
Orders::Actions::SendNotifications.call_async!(order: order, job_options: { queue_as: :my_queue, discard_on: ActiveJob::DeserializationError})
|
150
|
+
```
|
151
|
+
|
152
|
+
```ruby
|
150
153
|
# Important! Make sure your sidekiq configuration has 'my_queue' queue
|
151
154
|
```
|
152
155
|
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/readymade/action.rb
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
require 'active_job' unless defined?(::ActiveJob)
|
4
4
|
|
5
5
|
module Readymade
|
6
|
-
class BackgroundBangJob < ::
|
7
|
-
queue_as { self.arguments[0].fetch(:queue_as, :default) }
|
8
|
-
|
6
|
+
class BackgroundBangJob < ::Readymade::BackgroundJob
|
9
7
|
def perform(**args)
|
10
8
|
args.delete(:class_name).to_s.constantize.send(:call!, **args)
|
11
9
|
end
|
@@ -4,10 +4,39 @@ require 'active_job' unless defined?(::ActiveJob)
|
|
4
4
|
|
5
5
|
module Readymade
|
6
6
|
class BackgroundJob < ::ActiveJob::Base
|
7
|
-
queue_as
|
7
|
+
queue_as do
|
8
|
+
if (q = self.arguments[0][:queue_as]).present?
|
9
|
+
logger.warn "DEPRECATED: `queue_as` is deprecated. Use `job_options.queue_as` instead."
|
10
|
+
end
|
11
|
+
|
12
|
+
self.arguments[0].dig(:job_options, :queue_as).presence || q || 'default'
|
13
|
+
end
|
14
|
+
rescue_from StandardError, with: :handle_rescue_from
|
8
15
|
|
9
16
|
def perform(**args)
|
10
17
|
args.delete(:class_name).to_s.constantize.send(:call, **args)
|
11
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def handle_rescue_from(exception)
|
23
|
+
raise exception if job_options.blank? || job_options['discard_on'].blank?
|
24
|
+
|
25
|
+
discard_on = job_options['discard_on'].map { |d| d['value'] }
|
26
|
+
|
27
|
+
if discard_on.include?(exception.class.name)
|
28
|
+
logger.warn "Discarding job due to deserialization error: #{exception.message}"
|
29
|
+
# Discard the job without raising an error
|
30
|
+
else
|
31
|
+
logger.error "Job failed with deserialization error: #{exception.message}"
|
32
|
+
raise exception
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def job_options
|
39
|
+
@job_options ||= self.instance_variable_get('@serialized_arguments')[0]['job_options'] || {}
|
40
|
+
end
|
12
41
|
end
|
13
42
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Readymade
|
4
|
+
module Model
|
5
|
+
module ValidatableEnum
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def validatable_enum(*enums_to_fix)
|
10
|
+
enums_to_fix.each do |enum_name|
|
11
|
+
define_method(:"#{enum_name}=") do |value|
|
12
|
+
super(value)
|
13
|
+
rescue StandardError
|
14
|
+
instance_variable_set(:"@__bad_#{enum_name}", value)
|
15
|
+
super(nil)
|
16
|
+
end
|
17
|
+
|
18
|
+
validates enum_name, inclusion: {
|
19
|
+
in: send(enum_name.to_s.pluralize).keys,
|
20
|
+
message: lambda { |record, error|
|
21
|
+
val = record.instance_variable_get(:"@__bad_#{enum_name}")
|
22
|
+
return "#{error[:attribute]} is required" if val.nil?
|
23
|
+
|
24
|
+
"#{val.inspect} is not a valid #{error[:attribute]}"
|
25
|
+
}
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/readymade/response.rb
CHANGED
@@ -28,9 +28,23 @@ module Readymade
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def errors
|
31
|
+
return {} unless args.is_a?(Hash)
|
32
|
+
|
31
33
|
args[:errors].presence || {}
|
32
34
|
end
|
33
35
|
|
36
|
+
def humanized_errors
|
37
|
+
humanize_errors(errors)
|
38
|
+
end
|
39
|
+
|
40
|
+
def humanize_errors(errors)
|
41
|
+
if errors.is_a?(ActiveModel::Errors)
|
42
|
+
errors.full_messages.join('. ')
|
43
|
+
else
|
44
|
+
errors.map { |k, values| "#{k.to_s.humanize}: #{values.join(', ')}" }.join('. ')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
34
48
|
def consider_success?
|
35
49
|
@consider_success
|
36
50
|
end
|
data/lib/readymade/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: readymade
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- OrestF
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- Rakefile
|
100
100
|
- bin/console
|
101
101
|
- bin/setup
|
102
|
+
- lib/.DS_Store
|
102
103
|
- lib/readymade.rb
|
103
104
|
- lib/readymade/action.rb
|
104
105
|
- lib/readymade/background_bang_job.rb
|
@@ -108,6 +109,7 @@ files:
|
|
108
109
|
- lib/readymade/instant_form.rb
|
109
110
|
- lib/readymade/model/api_attachable.rb
|
110
111
|
- lib/readymade/model/filterable.rb
|
112
|
+
- lib/readymade/model/validatable_enum.rb
|
111
113
|
- lib/readymade/operation.rb
|
112
114
|
- lib/readymade/response.rb
|
113
115
|
- lib/readymade/version.rb
|
@@ -134,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
136
|
- !ruby/object:Gem::Version
|
135
137
|
version: '0'
|
136
138
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
139
|
+
rubygems_version: 3.4.19
|
138
140
|
signing_key:
|
139
141
|
specification_version: 4
|
140
142
|
summary: Set of base classes for ABDI architecture
|