readymade 0.3.0 → 0.3.6

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: f4e8e02d585f7ebcd9b83ddaef817e0116b8b06c80d543a46fbfb2df1adf99ca
4
- data.tar.gz: 333b90782eb4e24733f9073132f667f540b2f81c5b62d3dd92372ee434b0b9f3
3
+ metadata.gz: 90f0eb0091bea1e29078e83958d77aedfa989c39af4d21213bec81347f4d73df
4
+ data.tar.gz: b96a07f92350bee6be041456b979dc781ad1324ad8ef38e95547f9af34a250a8
5
5
  SHA512:
6
- metadata.gz: 202033d59da56afbc9a17b0eaf8659ed3fcd1fd4ff9c89d9687d429d636dbe61d22c450dc03ba15251b9d282ae6f7aa943caece163a23d8866f95d3798f58db5
7
- data.tar.gz: 3d02a2c554e9d4de2db20bbd598fa4c0d8da2757003358142cb61e7e71abf47b728a880b8f08c28824c8214c10711973376ed93550e2439ef98bb3d48c51ed34
6
+ metadata.gz: 82b0f5dbc204ea624d84c48edc4b6619216c300d447f1cae69a1828b88d4533b2048960757f2e354f5adf15400b993b2efff92e0e44f4e2c6e8e38a50a7a8221
7
+ data.tar.gz: 21b076ad062a65ed5afde67521ee433f99228cedf0d0b229079270e6f3793b7e4097a48ba02c9c81e7f5f84eedef8b0fc565f1ade7dbdfd518c91cbfb346227c
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.3.6] - 2023-07-21
5
+
6
+ * Add `queue_as: :name` argument to `Readymade::BackgroundJob` to select queue name when using `.call_async(args.merge(queue_as: :my_queue))`
7
+
8
+ ## [0.3.5] - 2023-06-23
9
+
10
+ * Add `.call!` method to `Readymade::Action` to raise an error if not success
11
+ * Add `.call_async!` method to `Readymade::Action` to raise an error in background if not success
12
+
4
13
  ## [0.3.0] - 2023-03-14
5
14
 
6
15
  * Add `.call_async` method to `Readymade::Action` to run service in background
data/Gemfile.lock CHANGED
@@ -1,32 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- readymade (0.3.0)
4
+ readymade (0.3.6)
5
5
  activejob
6
6
  activemodel
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activejob (6.1.4.1)
12
- activesupport (= 6.1.4.1)
11
+ activejob (7.0.5)
12
+ activesupport (= 7.0.5)
13
13
  globalid (>= 0.3.6)
14
- activemodel (6.1.4.1)
15
- activesupport (= 6.1.4.1)
16
- activesupport (6.1.4.1)
14
+ activemodel (7.0.5)
15
+ activesupport (= 7.0.5)
16
+ activesupport (7.0.5)
17
17
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
18
  i18n (>= 1.6, < 2)
19
19
  minitest (>= 5.1)
20
20
  tzinfo (~> 2.0)
21
- zeitwerk (~> 2.3)
22
21
  byebug (11.1.3)
23
- concurrent-ruby (1.1.9)
22
+ concurrent-ruby (1.2.2)
24
23
  diff-lcs (1.4.4)
25
24
  globalid (1.1.0)
26
25
  activesupport (>= 5.0)
27
- i18n (1.8.11)
26
+ i18n (1.14.1)
28
27
  concurrent-ruby (~> 1.0)
29
- minitest (5.14.4)
28
+ minitest (5.18.1)
30
29
  rake (13.0.6)
31
30
  rspec (3.10.0)
32
31
  rspec-core (~> 3.10.0)
@@ -41,9 +40,8 @@ GEM
41
40
  diff-lcs (>= 1.2.0, < 2.0)
42
41
  rspec-support (~> 3.10.0)
43
42
  rspec-support (3.10.3)
44
- tzinfo (2.0.4)
43
+ tzinfo (2.0.6)
45
44
  concurrent-ruby (~> 1.0)
46
- zeitwerk (2.5.1)
47
45
 
48
46
  PLATFORMS
49
47
  ruby
data/README.md CHANGED
@@ -146,6 +146,47 @@ 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) # job will be executed in 'my_queue'
150
+ # Important! Make sure your sidekiq configuration has 'my_queue' queue
151
+ ```
152
+
153
+
154
+ ### `.call!` - raise error unless response is success
155
+ (action must return Readymade::Response.new(:success))
156
+
157
+ ```ruby
158
+ class Orders::Actions::SendNotifications < Readymade::Action
159
+ def call!
160
+ send_email
161
+ return response(:fail, errors: errors) unless email_sent?
162
+ send_push
163
+ send_slack
164
+
165
+ response(:success, record: record, any_other_data: data)
166
+ end
167
+ ...
168
+ end
169
+
170
+ Orders::Actions::SendNotifications.call!(order: order) # raise error if response is fail
171
+ ```
172
+ ### `.call_async!` - runs in background and raise error unless response is success
173
+ (action must return Readymade::Response.new(:success))
174
+
175
+ ```ruby
176
+ class Orders::Actions::SendNotifications < Readymade::Action
177
+ def call!
178
+ send_email
179
+ return response(:fail, errors: errors) unless email_sent?
180
+ send_push
181
+ send_slack
182
+
183
+ response(:success, record: record, any_other_data: data)
184
+ end
185
+ ...
186
+ end
187
+
188
+ Orders::Actions::SendNotifications.call_async!(order: order) # job will be failed
189
+
149
190
  ```
150
191
 
151
192
  ### Readymade::Operation
@@ -2,19 +2,33 @@
2
2
 
3
3
  require 'readymade/response'
4
4
  require 'readymade/background_job'
5
+ require 'readymade/background_bang_job'
5
6
 
6
7
  module Readymade
7
8
  class Action
8
9
  class NonKeywordArgumentsError < StandardError; end
10
+ class UnSuccessError < StandardError; end
9
11
 
10
12
  def self.call(*args, &block)
11
13
  new(*args, &block).call
12
14
  end
13
15
 
16
+ def self.call!(*args, &block)
17
+ new(*args, &block).call!.then do |res|
18
+ raise UnSuccessError unless res.try(:success?)
19
+
20
+ res
21
+ end
22
+ end
23
+
14
24
  def self.call_async(*args, &block)
15
25
  new(*args, &block).call_async
16
26
  end
17
27
 
28
+ def self.call_async!(*args, &block)
29
+ new(*args, &block).call_async!
30
+ end
31
+
18
32
  attr_reader :args, :data
19
33
 
20
34
  def initialize(args = {})
@@ -28,10 +42,16 @@ module Readymade
28
42
 
29
43
  def call; end
30
44
 
45
+ def call!; end
46
+
31
47
  def call_async
32
48
  ::Readymade::BackgroundJob.perform_later(class_name: self.class.name, **args)
33
49
  end
34
50
 
51
+ def call_async!
52
+ ::Readymade::BackgroundBangJob.perform_later(class_name: self.class.name, **args)
53
+ end
54
+
35
55
  def response(status, *args)
36
56
  Response.new(status, *args)
37
57
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_job' unless defined?(::ActiveJob)
4
+
5
+ module Readymade
6
+ class BackgroundBangJob < ::ActiveJob::Base
7
+ queue_as { self.arguments[0].fetch(:queue_as, :default) }
8
+
9
+ def perform(**args)
10
+ args.delete(:class_name).to_s.constantize.send(:call!, **args)
11
+ end
12
+ end
13
+ end
@@ -4,7 +4,7 @@ require 'active_job' unless defined?(::ActiveJob)
4
4
 
5
5
  module Readymade
6
6
  class BackgroundJob < ::ActiveJob::Base
7
- # queue_as :default
7
+ queue_as { self.arguments[0].fetch(:queue_as, :default) }
8
8
 
9
9
  def perform(**args)
10
10
  args.delete(:class_name).to_s.constantize.send(:call, **args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Readymade
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.6'
5
5
  end
data/lib/readymade.rb CHANGED
@@ -4,6 +4,7 @@ require 'readymade/model/api_attachable'
4
4
  require 'readymade/model/filterable'
5
5
  require 'readymade/controller/serialization'
6
6
  require 'readymade/background_job'
7
+ require 'readymade/background_bang_job'
7
8
  require 'readymade/action'
8
9
  require 'readymade/form'
9
10
  require 'readymade/instant_form'
data/readymade.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.metadata['homepage_uri'] = spec.homepage
20
20
  spec.metadata['source_code_uri'] = spec.homepage
21
- spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
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.3.0
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - OrestF
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-14 00:00:00.000000000 Z
11
+ date: 2023-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -101,6 +101,7 @@ files:
101
101
  - bin/setup
102
102
  - lib/readymade.rb
103
103
  - lib/readymade/action.rb
104
+ - lib/readymade/background_bang_job.rb
104
105
  - lib/readymade/background_job.rb
105
106
  - lib/readymade/controller/serialization.rb
106
107
  - lib/readymade/form.rb
@@ -117,7 +118,7 @@ licenses:
117
118
  metadata:
118
119
  homepage_uri: https://github.com/OrestF/readymade
119
120
  source_code_uri: https://github.com/OrestF/readymade
120
- changelog_uri: https://github.com/OrestF/readymade/CHANGELOG.md
121
+ changelog_uri: https://github.com/OrestF/readymade/blob/master/CHANGELOG.md
121
122
  post_install_message:
122
123
  rdoc_options: []
123
124
  require_paths: