operationable 0.1.7 → 0.1.8
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/README.md +98 -5
- data/lib/operationable/runners/base.rb +4 -5
- data/lib/operationable/version.rb +1 -1
- data/operationable-0.1.7.gem +0 -0
- metadata +2 -8
- data/operationable-0.1.0.gem +0 -0
- data/operationable-0.1.1.gem +0 -0
- data/operationable-0.1.2.gem +0 -0
- data/operationable-0.1.3.gem +0 -0
- data/operationable-0.1.4.gem +0 -0
- data/operationable-0.1.5.gem +0 -0
- data/operationable-0.1.6.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b48986600bb3d52c71cc98dfae222e6176174c
|
4
|
+
data.tar.gz: 0dc6951d98772dba0340786efecbb05ae19f1541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46c5261c17ac837b67ef19a3fb4bc9e0bffb7295fa92f5cfcf006416c0d6916fbadc816b238be85f1fed81803f2a83e0ef9ba32c37930d02c76262218ee57825
|
7
|
+
data.tar.gz: 0ff656bb174f40715220172692e2911676cb8411a0c3ffa8b83c1bb189157b919be871bfd50f5458102ceea8719fcd20ca9d61ee54858085f9cfced4c3dff056
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Operationable
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This gem is solving the problem with ActiveRecord callbacks hell.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,98 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Call operation at your controllers
|
24
|
+
|
25
|
+
```
|
26
|
+
class EntityController < ApplicationController
|
27
|
+
def create
|
28
|
+
op = EntityOperation::Create.new(@entity, current_user)
|
29
|
+
|
30
|
+
if op.process
|
31
|
+
render json: @entity, status: :created
|
32
|
+
else
|
33
|
+
render json: { errors: @entity.errors }, status: :unprocessable_entity
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Move you model callbacks to operation
|
40
|
+
|
41
|
+
|
42
|
+
```
|
43
|
+
module EntityOperation
|
44
|
+
class Create < Operationable::Create
|
45
|
+
class Builder < Operationable::Builder
|
46
|
+
def build
|
47
|
+
record
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class Serializer < Operationable::Serializer
|
52
|
+
RECORD_FIELDS = [].freeze
|
53
|
+
USER_FIELDS = %i(id role email name).freeze
|
54
|
+
end
|
55
|
+
|
56
|
+
class Specification < Operationable::Specification
|
57
|
+
def should_callback_one
|
58
|
+
true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Runner < Operationable::Runners::Separate
|
63
|
+
def initialize_callbacks
|
64
|
+
push_to_queue(:callback_one)
|
65
|
+
push_to_queue(:callback_two, :low)
|
66
|
+
push_to_queue(:callback_three, :high)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class Callback < Operationable::Callback
|
71
|
+
def callback_one
|
72
|
+
AnotherEntities.update_all(field: 123)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
#Operation
|
80
|
+
|
81
|
+
Exiting operations: create, update, destroy or use raw Operationable::Operation.
|
82
|
+
Operationable::Create(Update, Destory) inherited from Operationable::Operation
|
83
|
+
|
84
|
+
#Builder
|
85
|
+
|
86
|
+
Builder useful for that things you usually do at before_create/update/destroy callbacks.
|
87
|
+
|
88
|
+
#Specification
|
89
|
+
|
90
|
+
Specification decides run or not run callback based on boolean value returned from should_ prefixed callback name.
|
91
|
+
If specification not described, callback will called at any case.
|
92
|
+
|
93
|
+
#Runner
|
94
|
+
|
95
|
+
Exists two types for Runners - Serial and Separate runner. Serial callbacks will run one after another, at described order.
|
96
|
+
Separate runners not related one for another and can be run simultaneously.
|
97
|
+
|
98
|
+
Serial adapter creates one background job, separate for each callback.
|
99
|
+
|
100
|
+
push_to_queue(callback_name, queue_name) if queue_name not passed, callback will run synchronously
|
101
|
+
|
102
|
+
Operations work via ActiveJob, so you can use any adapter that you want.
|
103
|
+
|
104
|
+
#Serializer
|
105
|
+
|
106
|
+
Serializer used to define what values should be passed to job(redis do not accept AR instances or other complex structures).
|
107
|
+
Also you don't need all record fields should passed to callbacks.
|
108
|
+
|
109
|
+
#Callback
|
110
|
+
|
111
|
+
Class that contain callback methods, that will called after model saved in runtime or in background
|
112
|
+
|
113
|
+
#Validators
|
114
|
+
TODO: describe validators
|
26
115
|
|
27
116
|
## Development
|
28
117
|
|
@@ -32,7 +121,11 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
121
|
|
33
122
|
## Contributing
|
34
123
|
|
35
|
-
|
124
|
+
Contributions are welcome!
|
125
|
+
|
126
|
+
Contributors:
|
127
|
+
[korbutvitaliy](https://github.com/korbutvitaliy)
|
128
|
+
[kirillsuhodolov](https://github.com/KirillSuhodolov)
|
36
129
|
|
37
130
|
|
38
131
|
## License
|
@@ -26,11 +26,10 @@ module Operationable
|
|
26
26
|
def initialize_callbacks
|
27
27
|
end
|
28
28
|
|
29
|
-
def push_to_queue(
|
30
|
-
|
31
|
-
callback_method_name: callback_method_name.to_s,
|
32
|
-
|
33
|
-
}
|
29
|
+
def push_to_queue(*callback_method_names, queue: nil)
|
30
|
+
callback_method_names.each do |callback_method_name|
|
31
|
+
callbacks << { callback_method_name: callback_method_name.to_s, queue: queue.to_s }
|
32
|
+
end
|
34
33
|
end
|
35
34
|
|
36
35
|
def callback_names
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: operationable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Suhodolov
|
@@ -99,13 +99,7 @@ files:
|
|
99
99
|
- lib/operations/create.rb
|
100
100
|
- lib/operations/destroy.rb
|
101
101
|
- lib/operations/update.rb
|
102
|
-
- operationable-0.1.
|
103
|
-
- operationable-0.1.1.gem
|
104
|
-
- operationable-0.1.2.gem
|
105
|
-
- operationable-0.1.3.gem
|
106
|
-
- operationable-0.1.4.gem
|
107
|
-
- operationable-0.1.5.gem
|
108
|
-
- operationable-0.1.6.gem
|
102
|
+
- operationable-0.1.7.gem
|
109
103
|
- operationable.gemspec
|
110
104
|
- spec/operationable_spec.rb
|
111
105
|
- spec/spec_helper.rb
|
data/operationable-0.1.0.gem
DELETED
Binary file
|
data/operationable-0.1.1.gem
DELETED
Binary file
|
data/operationable-0.1.2.gem
DELETED
Binary file
|
data/operationable-0.1.3.gem
DELETED
Binary file
|
data/operationable-0.1.4.gem
DELETED
Binary file
|
data/operationable-0.1.5.gem
DELETED
Binary file
|
data/operationable-0.1.6.gem
DELETED
Binary file
|