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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ade6d51c19fadefd0b41528d0f81f1da2ddbdf6
4
- data.tar.gz: b890c49175142c5ed3067f407e52117dffbef8e5
3
+ metadata.gz: c0b48986600bb3d52c71cc98dfae222e6176174c
4
+ data.tar.gz: 0dc6951d98772dba0340786efecbb05ae19f1541
5
5
  SHA512:
6
- metadata.gz: 3466d1c15547a9b30dd3e32442f5bf2785c9255edd647681f2b7ce5126e7b7c3ff4ea1b82c4ce73dfe44f06048037b1212f10277dedac359862b20b2b92e3a43
7
- data.tar.gz: f3ba44086bc63975640ae53b77f26b21bed05d649d7e8bcec466d96fa241e152b1e822fdef7ec3cb0cb430d7ae51adf411d65c1d148bc4b07b260e346fce535c
6
+ metadata.gz: 46c5261c17ac837b67ef19a3fb4bc9e0bffb7295fa92f5cfcf006416c0d6916fbadc816b238be85f1fed81803f2a83e0ef9ba32c37930d02c76262218ee57825
7
+ data.tar.gz: 0ff656bb174f40715220172692e2911676cb8411a0c3ffa8b83c1bb189157b919be871bfd50f5458102ceea8719fcd20ca9d61ee54858085f9cfced4c3dff056
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Operationable
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/operationable`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/operationable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
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(callback_method_name, queue=nil)
30
- callbacks << {
31
- callback_method_name: callback_method_name.to_s,
32
- queue: queue.to_s
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
@@ -1,3 +1,3 @@
1
1
  module Operationable
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
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.7
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.0.gem
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
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file