readymade 0.3.0 → 0.3.5

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: f4e8e02d585f7ebcd9b83ddaef817e0116b8b06c80d543a46fbfb2df1adf99ca
4
- data.tar.gz: 333b90782eb4e24733f9073132f667f540b2f81c5b62d3dd92372ee434b0b9f3
3
+ metadata.gz: f6af81b9c83a1dad8f64ead23ebe956ffe8341308c3acef6211a9c76fa5df5fb
4
+ data.tar.gz: d6cda3a6863ce1330df753de6e6fd51c8f0005e05b0aa8d10534b59eb5b6104f
5
5
  SHA512:
6
- metadata.gz: 202033d59da56afbc9a17b0eaf8659ed3fcd1fd4ff9c89d9687d429d636dbe61d22c450dc03ba15251b9d282ae6f7aa943caece163a23d8866f95d3798f58db5
7
- data.tar.gz: 3d02a2c554e9d4de2db20bbd598fa4c0d8da2757003358142cb61e7e71abf47b728a880b8f08c28824c8214c10711973376ed93550e2439ef98bb3d48c51ed34
6
+ metadata.gz: 7f05bc204146596fd641f742d6ee2738dfc8db887ddb35c1588f1a1aa1639f80fc334920333206e2392999ea7c01f9db42c585b356ec33cfa9ec528cec0249f2
7
+ data.tar.gz: 1d7196a1c79a79169bcf865406dca0aa8bdfcfb07d7e659616fe2563260b3dbfcc95ed8f19c3f43eca7242e7acd573648629a90cce803495474b2289cc408d19
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Changelog
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
+ ## [0.4.0] - 2023-06-22
5
+
6
+ * Add `.call!` method to `Readymade::Action` to raise an error if not success
7
+ * Add `.call_async!` method to `Readymade::Action` to raise an error in background if not success
8
+
4
9
  ## [0.3.0] - 2023-03-14
5
10
 
6
11
  * 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.5)
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
@@ -148,6 +148,44 @@ end
148
148
  Orders::Actions::SendNotifications.call_async(order: order)
149
149
  ```
150
150
 
151
+
152
+ ### `.call!` - raise error unless response is success
153
+ (action must return Readymade::Response.new(:success))
154
+
155
+ ```ruby
156
+ class Orders::Actions::SendNotifications < Readymade::Action
157
+ def call!
158
+ send_email
159
+ return response(:fail, errors: errors) unless email_sent?
160
+ send_push
161
+ send_slack
162
+
163
+ response(:success, record: record, any_other_data: data)
164
+ end
165
+ ...
166
+ end
167
+
168
+ Orders::Actions::SendNotifications.call!(order: order) # raise error if response is fail
169
+ ```
170
+ ### `.call_async!` - runs in background and raise error unless response is success
171
+ (action must return Readymade::Response.new(:success))
172
+
173
+ ```ruby
174
+ class Orders::Actions::SendNotifications < Readymade::Action
175
+ def call!
176
+ send_email
177
+ return response(:fail, errors: errors) unless email_sent?
178
+ send_push
179
+ send_slack
180
+
181
+ response(:success, record: record, any_other_data: data)
182
+ end
183
+ ...
184
+ end
185
+
186
+ Orders::Actions::SendNotifications.call_async!(order: order) # job will be failed
187
+ ```
188
+
151
189
  ### Readymade::Operation
152
190
 
153
191
  Provides set of help methods like: `build_form`, `form_valid?`, `validation_fail`, `save_record`, etc.
@@ -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 :default
8
+
9
+ def perform(**args)
10
+ args.delete(:class_name).to_s.constantize.send(:call!, **args)
11
+ end
12
+ end
13
+ end
@@ -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.5'
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'
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.5
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-06-23 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