readymade 0.2.8 → 0.3.5
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/.gitignore +1 -0
- data/CHANGELOG.md +9 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +15 -11
- data/README.md +55 -0
- data/lib/readymade/action.rb +29 -0
- data/lib/readymade/background_bang_job.rb +13 -0
- data/lib/readymade/background_job.rb +13 -0
- data/lib/readymade/version.rb +1 -1
- data/lib/readymade.rb +2 -0
- data/readymade.gemspec +3 -0
- metadata +32 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6af81b9c83a1dad8f64ead23ebe956ffe8341308c3acef6211a9c76fa5df5fb
|
|
4
|
+
data.tar.gz: d6cda3a6863ce1330df753de6e6fd51c8f0005e05b0aa8d10534b59eb5b6104f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f05bc204146596fd641f742d6ee2738dfc8db887ddb35c1588f1a1aa1639f80fc334920333206e2392999ea7c01f9db42c585b356ec33cfa9ec528cec0249f2
|
|
7
|
+
data.tar.gz: 1d7196a1c79a79169bcf865406dca0aa8bdfcfb07d7e659616fe2563260b3dbfcc95ed8f19c3f43eca7242e7acd573648629a90cce803495474b2289cc408d19
|
data/.gitignore
CHANGED
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.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
|
+
|
|
9
|
+
## [0.3.0] - 2023-03-14
|
|
10
|
+
|
|
11
|
+
* Add `.call_async` method to `Readymade::Action` to run service in background
|
|
12
|
+
|
|
4
13
|
## [0.2.8] - 2022-11-10
|
|
5
14
|
|
|
6
15
|
### Fixes
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,25 +1,31 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
readymade (0.
|
|
4
|
+
readymade (0.3.5)
|
|
5
|
+
activejob
|
|
6
|
+
activemodel
|
|
5
7
|
|
|
6
8
|
GEM
|
|
7
9
|
remote: https://rubygems.org/
|
|
8
10
|
specs:
|
|
9
|
-
|
|
10
|
-
activesupport (=
|
|
11
|
-
|
|
11
|
+
activejob (7.0.5)
|
|
12
|
+
activesupport (= 7.0.5)
|
|
13
|
+
globalid (>= 0.3.6)
|
|
14
|
+
activemodel (7.0.5)
|
|
15
|
+
activesupport (= 7.0.5)
|
|
16
|
+
activesupport (7.0.5)
|
|
12
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
13
18
|
i18n (>= 1.6, < 2)
|
|
14
19
|
minitest (>= 5.1)
|
|
15
20
|
tzinfo (~> 2.0)
|
|
16
|
-
zeitwerk (~> 2.3)
|
|
17
21
|
byebug (11.1.3)
|
|
18
|
-
concurrent-ruby (1.
|
|
22
|
+
concurrent-ruby (1.2.2)
|
|
19
23
|
diff-lcs (1.4.4)
|
|
20
|
-
|
|
24
|
+
globalid (1.1.0)
|
|
25
|
+
activesupport (>= 5.0)
|
|
26
|
+
i18n (1.14.1)
|
|
21
27
|
concurrent-ruby (~> 1.0)
|
|
22
|
-
minitest (5.
|
|
28
|
+
minitest (5.18.1)
|
|
23
29
|
rake (13.0.6)
|
|
24
30
|
rspec (3.10.0)
|
|
25
31
|
rspec-core (~> 3.10.0)
|
|
@@ -34,15 +40,13 @@ GEM
|
|
|
34
40
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
35
41
|
rspec-support (~> 3.10.0)
|
|
36
42
|
rspec-support (3.10.3)
|
|
37
|
-
tzinfo (2.0.
|
|
43
|
+
tzinfo (2.0.6)
|
|
38
44
|
concurrent-ruby (~> 1.0)
|
|
39
|
-
zeitwerk (2.5.1)
|
|
40
45
|
|
|
41
46
|
PLATFORMS
|
|
42
47
|
ruby
|
|
43
48
|
|
|
44
49
|
DEPENDENCIES
|
|
45
|
-
activemodel
|
|
46
50
|
byebug
|
|
47
51
|
rake
|
|
48
52
|
readymade!
|
data/README.md
CHANGED
|
@@ -131,6 +131,61 @@ response.data[:record]
|
|
|
131
131
|
response.data[:any_other_data]
|
|
132
132
|
```
|
|
133
133
|
|
|
134
|
+
### `.call_async` - any action could we call async (using ActiveJob)
|
|
135
|
+
|
|
136
|
+
```ruby
|
|
137
|
+
class Orders::Actions::SendNotifications < Readymade::Action
|
|
138
|
+
def call
|
|
139
|
+
send_email
|
|
140
|
+
send_push
|
|
141
|
+
send_slack
|
|
142
|
+
|
|
143
|
+
response(:success, record: record, any_other_data: data)
|
|
144
|
+
end
|
|
145
|
+
...
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
Orders::Actions::SendNotifications.call_async(order: order)
|
|
149
|
+
```
|
|
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
|
+
|
|
134
189
|
### Readymade::Operation
|
|
135
190
|
|
|
136
191
|
Provides set of help methods like: `build_form`, `form_valid?`, `validation_fail`, `save_record`, etc.
|
data/lib/readymade/action.rb
CHANGED
|
@@ -1,15 +1,34 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'readymade/response'
|
|
4
|
+
require 'readymade/background_job'
|
|
5
|
+
require 'readymade/background_bang_job'
|
|
4
6
|
|
|
5
7
|
module Readymade
|
|
6
8
|
class Action
|
|
7
9
|
class NonKeywordArgumentsError < StandardError; end
|
|
10
|
+
class UnSuccessError < StandardError; end
|
|
8
11
|
|
|
9
12
|
def self.call(*args, &block)
|
|
10
13
|
new(*args, &block).call
|
|
11
14
|
end
|
|
12
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
|
+
|
|
24
|
+
def self.call_async(*args, &block)
|
|
25
|
+
new(*args, &block).call_async
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.call_async!(*args, &block)
|
|
29
|
+
new(*args, &block).call_async!
|
|
30
|
+
end
|
|
31
|
+
|
|
13
32
|
attr_reader :args, :data
|
|
14
33
|
|
|
15
34
|
def initialize(args = {})
|
|
@@ -23,6 +42,16 @@ module Readymade
|
|
|
23
42
|
|
|
24
43
|
def call; end
|
|
25
44
|
|
|
45
|
+
def call!; end
|
|
46
|
+
|
|
47
|
+
def call_async
|
|
48
|
+
::Readymade::BackgroundJob.perform_later(class_name: self.class.name, **args)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def call_async!
|
|
52
|
+
::Readymade::BackgroundBangJob.perform_later(class_name: self.class.name, **args)
|
|
53
|
+
end
|
|
54
|
+
|
|
26
55
|
def response(status, *args)
|
|
27
56
|
Response.new(status, *args)
|
|
28
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
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_job' unless defined?(::ActiveJob)
|
|
4
|
+
|
|
5
|
+
module Readymade
|
|
6
|
+
class BackgroundJob < ::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
|
data/lib/readymade/version.rb
CHANGED
data/lib/readymade.rb
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
require 'readymade/model/api_attachable'
|
|
4
4
|
require 'readymade/model/filterable'
|
|
5
5
|
require 'readymade/controller/serialization'
|
|
6
|
+
require 'readymade/background_job'
|
|
7
|
+
require 'readymade/background_bang_job'
|
|
6
8
|
require 'readymade/action'
|
|
7
9
|
require 'readymade/form'
|
|
8
10
|
require 'readymade/instant_form'
|
data/readymade.gemspec
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
|
+
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:
|
|
11
|
+
date: 2023-06-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|
|
@@ -52,6 +52,34 @@ dependencies:
|
|
|
52
52
|
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
54
|
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: activemodel
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
type: :runtime
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: activejob
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :runtime
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
55
83
|
description: Set of base classes for ABDI architecture
|
|
56
84
|
email:
|
|
57
85
|
- falchuko@gmail.com
|
|
@@ -73,6 +101,8 @@ files:
|
|
|
73
101
|
- bin/setup
|
|
74
102
|
- lib/readymade.rb
|
|
75
103
|
- lib/readymade/action.rb
|
|
104
|
+
- lib/readymade/background_bang_job.rb
|
|
105
|
+
- lib/readymade/background_job.rb
|
|
76
106
|
- lib/readymade/controller/serialization.rb
|
|
77
107
|
- lib/readymade/form.rb
|
|
78
108
|
- lib/readymade/instant_form.rb
|