operationable 0.6.0 → 0.7.0
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/lib/operationable.rb +0 -4
- data/lib/operationable/callback.rb +4 -0
- data/lib/operationable/operation.rb +9 -1
- data/lib/operationable/runners/base.rb +38 -0
- data/lib/operationable/runners/separate.rb +23 -6
- data/lib/operationable/serializer.rb +2 -2
- data/lib/operationable/version.rb +1 -1
- metadata +2 -5
- data/lib/operations/create.rb +0 -8
- data/lib/operations/destroy.rb +0 -8
- data/lib/operations/update.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fd1e53ce750855eed63256b1df0d140f502043e9355baa2c3592c5c12430e00
|
4
|
+
data.tar.gz: 4c4f0c4ccf6a67f4c2c016e05a4f3dab4c149338dbcefa5e154a2d17d820b346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afc4520e8d990fcf27b0065e272b14173986d1904b179dfb31033635694fb8b83f1443fb2c11559ef17998f5163f08e93474bcf9b715e48834a727fc81ffc828
|
7
|
+
data.tar.gz: 8200c85e7a02990d9df672c6325c95f2b47bf4fcbc0e805030fa2ee7b65eba9398e9cf71351f240f277b58ab71d30c0fda9f267b55a9546eb1197ed1ef1ec3d4
|
data/lib/operationable.rb
CHANGED
@@ -15,10 +15,6 @@ require 'operationable/runners/base'
|
|
15
15
|
require 'operationable/runners/serial'
|
16
16
|
require 'operationable/runners/separate'
|
17
17
|
|
18
|
-
# require 'operations/create'
|
19
|
-
# require 'operations/destroy'
|
20
|
-
# require 'operations/update'
|
21
|
-
|
22
18
|
module Operationable
|
23
19
|
class Operation
|
24
20
|
class Builder < ::Operationable::Builder; end
|
@@ -28,9 +28,13 @@ module Operationable
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def persist
|
31
|
-
record
|
31
|
+
save_record(record)
|
32
32
|
end
|
33
33
|
|
34
|
+
def save_record(record)
|
35
|
+
record
|
36
|
+
end
|
37
|
+
|
34
38
|
def build
|
35
39
|
"#{class_name}::Builder".constantize.new(record, user, params).build
|
36
40
|
end
|
@@ -42,5 +46,9 @@ module Operationable
|
|
42
46
|
def class_name
|
43
47
|
self.class.name
|
44
48
|
end
|
49
|
+
|
50
|
+
def operation_name
|
51
|
+
self.class.to_s.split('::').last(2).map(&:underscore).join(':')
|
52
|
+
end
|
45
53
|
end
|
46
54
|
end
|
@@ -1,9 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Operationable
|
3
3
|
module Runners
|
4
|
+
module Wrappable
|
5
|
+
def push_to_queue(*callback_method_names, job_class_name: nil, queue: nil, params: {})
|
6
|
+
callback_method_names.each do |callback_method_name|
|
7
|
+
callbacks << {
|
8
|
+
callback_method_name: callback_method_name.to_s,
|
9
|
+
job_class_name: job_class_name.nil? ? job_class.to_s : job_class_name.to_s,
|
10
|
+
queue: (job_class_name && queue.blank?) ? job_class_name.to_s.constantize.queue_name : queue.to_s,
|
11
|
+
params: params
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_part(modul, opts=nil)
|
17
|
+
modul.execute(self, opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def callbacks
|
21
|
+
@callbacks ||= []
|
22
|
+
end
|
23
|
+
|
24
|
+
def inherited_callbacks
|
25
|
+
ancestors
|
26
|
+
.grep(Wrappable)
|
27
|
+
.reverse
|
28
|
+
.flat_map(&:callbacks)
|
29
|
+
end
|
30
|
+
|
31
|
+
def new(*arguments, &block)
|
32
|
+
instance = allocate
|
33
|
+
instance.send(:initialize, *arguments, &block)
|
34
|
+
instance_callbacks = instance.instance_variable_get(:@callbacks)
|
35
|
+
instance.instance_variable_set(:@callbacks, instance_callbacks.concat(inherited_callbacks).uniq)
|
36
|
+
instance
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
4
40
|
class Base
|
5
41
|
attr_reader :callbacks, :record, :user, :params, :result
|
6
42
|
|
43
|
+
extend Wrappable
|
44
|
+
|
7
45
|
def initialize(record, params, result, user)
|
8
46
|
@record = record
|
9
47
|
@params = params
|
@@ -11,10 +11,10 @@ module Operationable
|
|
11
11
|
# callback_class = callback_method_name.to_s.safe_constantize
|
12
12
|
|
13
13
|
args = {
|
14
|
-
q_options: q_options(callback_method_name, queue),
|
15
|
-
props: props.merge(params)
|
16
|
-
}
|
17
|
-
|
14
|
+
q_options: q_options(callback_method_name, queue).to_h,
|
15
|
+
props: props.merge(params).to_h
|
16
|
+
}.to_h.deep_stringify_keys
|
17
|
+
|
18
18
|
queue.blank? ? self.class.call(args) : perform(job_class_name, args, get_delayed_params(callback_method_name))
|
19
19
|
end
|
20
20
|
|
@@ -30,8 +30,25 @@ module Operationable
|
|
30
30
|
queue: queue })
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
class << self
|
34
|
+
def operation_name
|
35
|
+
self.to_s.split('::').last(3).first(2).map(&:underscore).join(':')
|
36
|
+
end
|
37
|
+
|
38
|
+
def call(params)
|
39
|
+
q_options = extract_q_options(params)
|
40
|
+
props = extract_props(params)
|
41
|
+
|
42
|
+
q_options[:callback_class_name].constantize.new(props, q_options).method(q_options[:callback_method_name]).call
|
43
|
+
end
|
44
|
+
|
45
|
+
def extract_props(params)
|
46
|
+
params['props'].deep_symbolize_keys
|
47
|
+
end
|
48
|
+
|
49
|
+
def extract_q_options(params)
|
50
|
+
params['q_options'].deep_symbolize_keys
|
51
|
+
end
|
35
52
|
end
|
36
53
|
end
|
37
54
|
end
|
@@ -63,8 +63,8 @@ module Operationable
|
|
63
63
|
params.transform_values! do |value|
|
64
64
|
if value.is_a? Array
|
65
65
|
value.map { |i| acceptable_argument?(i) ? i : i.to_s }
|
66
|
-
elsif value.is_a?
|
67
|
-
stringify_arguments(value)
|
66
|
+
elsif [Hash, HashWithIndifferentAccess, ActionController::Parameters].any? { |klass| value.is_a? klass }
|
67
|
+
stringify_arguments(value.to_h)
|
68
68
|
else
|
69
69
|
acceptable_argument?(value) ? value : value.to_s
|
70
70
|
end
|
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.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Suhodolov
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-04-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -82,9 +82,6 @@ files:
|
|
82
82
|
- lib/operationable/serializer.rb
|
83
83
|
- lib/operationable/specification.rb
|
84
84
|
- lib/operationable/version.rb
|
85
|
-
- lib/operations/create.rb
|
86
|
-
- lib/operations/destroy.rb
|
87
|
-
- lib/operations/update.rb
|
88
85
|
- operationable.gemspec
|
89
86
|
- spec/operationable_spec.rb
|
90
87
|
- spec/spec_helper.rb
|
data/lib/operations/create.rb
DELETED
data/lib/operations/destroy.rb
DELETED