operationable 0.2.4 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba4f68a864b7430a94ab73c82f58c556a251aecd
4
- data.tar.gz: 33af1348f7da1d56c5caeee3aae8654f8e25b6fd
3
+ metadata.gz: da4f2c001b58a3ce07d7d7a16100c9abdee28cd2
4
+ data.tar.gz: 52b9abff75acce3b938c60708e10646e79fb7a98
5
5
  SHA512:
6
- metadata.gz: 7d655c4b3c5c320be0fd90a458dc533b8abe2d3d9133af243dce47f1730aa08b7847807046904a50bbe6bfd4910411f65032187ae7849a164c402ecfcf5f277f
7
- data.tar.gz: b7117faa87f4a64fbf73d440c8c2213e33dec571003c5355c477e6602100136a0c696542276f5f61d1f686dd4ab6d2739a23d31124715333b50a6e3264740a5a
6
+ metadata.gz: 907b157d42743139639ee5999ad221e25b576bb33a802078db1a9f18f5e3047502c4844f6957f1c41001168e7d518fac48265075aa1b475ba2bbcde17441e275
7
+ data.tar.gz: 19838de1878f31a759c11002d42ff0c1bd301f8a794e310cdd477965bcf81f0a05deb58714d76df99d7863627a2fe14911aefb748c533a1463d6f5a7f53b6882
@@ -8,6 +8,7 @@ require 'operationable/callback'
8
8
  require 'operationable/operation'
9
9
  require 'operationable/serializer'
10
10
  require 'operationable/specification'
11
+ require 'operationable/persister'
11
12
 
12
13
  require 'operationable/runners/base'
13
14
  require 'operationable/runners/serial'
@@ -24,5 +25,6 @@ module Operationable
24
25
  class Callback < ::Operationable::Callback; end
25
26
  class Specification < ::Operationable::Specification; end
26
27
  class Serializer < ::Operationable::Serializer; end
28
+ class Persister < ::Operationable::Persister; end
27
29
  end
28
30
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+ module Operationable
3
+ class Persister
4
+ class << self
5
+ def persist(callbacks, initiator_id, params, name)
6
+ ::Operation.create(
7
+ callbacks: callbacks.map { |callback|
8
+ {
9
+ status: ::Operation::STATUS_INIT,
10
+ name: callback[:callback_method_name],
11
+ queue: callback[:queue]
12
+ }
13
+ },
14
+ initiator_id: initiator_id,
15
+ params: params,
16
+ name: name
17
+ )
18
+ end
19
+
20
+ def working(id, name)
21
+ update(id, name, ::Operation::STATUS_WORKING)
22
+ end
23
+
24
+ def completed(id, name)
25
+ update(id, name, ::Operation::STATUS_COMPLETED)
26
+ end
27
+
28
+ def around_call(id, name, block)
29
+ working(id, name)
30
+ block.call
31
+ completed(id, name)
32
+ end
33
+
34
+ private
35
+
36
+ def update(id, name, status)
37
+ op = ::Operation.find(id)
38
+ callbacks = op.callbacks.map do |cb|
39
+ cb['status'] = status if cb['name'] === name
40
+ cb
41
+ end
42
+
43
+ op.callbacks = callbacks
44
+ op.save
45
+ end
46
+ end
47
+ end
48
+ end
@@ -12,6 +12,8 @@ module Operationable
12
12
  @callbacks = []
13
13
 
14
14
  initialize_callbacks
15
+
16
+ persist_operation
15
17
  end
16
18
 
17
19
  def run
@@ -19,6 +21,10 @@ module Operationable
19
21
 
20
22
  private
21
23
 
24
+ def persist_operation
25
+ @persist_operation ||= ::Operationable::Persister.persist(check_callbacks, user.id, props, operation_class_name)
26
+ end
27
+
22
28
  def props
23
29
  serializer_instance.serialize
24
30
  end
@@ -14,12 +14,20 @@ module Operationable
14
14
  { type: 'separate',
15
15
  callback_class_name: callback_class_name,
16
16
  callback_method_name: callback_method_name,
17
- queue: queue }
17
+ queue: queue,
18
+ op_id: persist_operation.id }
18
19
  end
19
20
 
21
+ # def self.call(options, props)
22
+ # options[:callback_class_name].constantize.new(props).method(options[:callback_method_name]).call
23
+ # end
24
+
20
25
  def self.call(options, props)
21
- options[:callback_class_name].constantize.new(props).method(options[:callback_method_name]).call
26
+ ::Operationable::Persister.around_call(options[:op_id], options[:callback_method_name], -> {
27
+ options[:callback_class_name].constantize.new(props).method(options[:callback_method_name]).call
28
+ })
22
29
  end
30
+
23
31
  end
24
32
  end
25
33
  end
@@ -10,16 +10,27 @@ module Operationable
10
10
  (queue.blank? ? self.class : OperationJob.method(perform_method)).call(options, props)
11
11
  end
12
12
 
13
+ # def self.call(options, props)
14
+ # instance = options[:callback_class_name].constantize.new(props)
15
+ # options[:callback_names].each { |method_name| instance.method(method_name).call }
16
+ # end
17
+
13
18
  def self.call(options, props)
14
19
  instance = options[:callback_class_name].constantize.new(props)
15
- options[:callback_names].each { |method_name| instance.method(method_name).call }
20
+
21
+ options[:callback_names].each do |method_name|
22
+ ::Operationable::Persister.around_call(options[:op_id], method_name, -> {
23
+ instance.method(method_name).call
24
+ })
25
+ end
16
26
  end
17
27
 
18
28
  def options
19
29
  { type: 'serial',
20
30
  callback_class_name: callback_class_name,
21
31
  callback_names: callback_names,
22
- queue: queue }
32
+ queue: queue,
33
+ op_id: persist_operation.id }
23
34
  end
24
35
 
25
36
  private
@@ -22,7 +22,13 @@ module Operationable
22
22
  private
23
23
 
24
24
  def extract_props(record, user)
25
- { **extract_from_record(record), **extract_from_user(user), activity: activity, action_name: action_name }
25
+ {
26
+ **extract_from_record(record),
27
+ **extract_from_user(user),
28
+ params: params,
29
+ activity: activity,
30
+ action_name: action_name
31
+ }
26
32
  end
27
33
 
28
34
  def extract_from_record(record)
@@ -1,3 +1,3 @@
1
1
  module Operationable
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  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.2.4
4
+ version: 0.2.5
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: 2017-01-28 00:00:00.000000000 Z
12
+ date: 2017-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activejob
@@ -90,6 +90,7 @@ files:
90
90
  - lib/operationable/builder.rb
91
91
  - lib/operationable/callback.rb
92
92
  - lib/operationable/operation.rb
93
+ - lib/operationable/persister.rb
93
94
  - lib/operationable/runners/base.rb
94
95
  - lib/operationable/runners/separate.rb
95
96
  - lib/operationable/runners/serial.rb
@@ -99,13 +100,6 @@ files:
99
100
  - lib/operations/create.rb
100
101
  - lib/operations/destroy.rb
101
102
  - lib/operations/update.rb
102
- - operationable-0.1.7.gem
103
- - operationable-0.1.8.gem
104
- - operationable-0.1.9.gem
105
- - operationable-0.2.0.gem
106
- - operationable-0.2.1.gem
107
- - operationable-0.2.2.gem
108
- - operationable-0.2.3.gem
109
103
  - operationable.gemspec
110
104
  - spec/operationable_spec.rb
111
105
  - spec/spec_helper.rb
@@ -129,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
123
  version: '0'
130
124
  requirements: []
131
125
  rubyforge_project:
132
- rubygems_version: 2.5.1
126
+ rubygems_version: 2.6.10
133
127
  signing_key:
134
128
  specification_version: 4
135
129
  summary: Implementation of command pattern to avoid ActiveRecord callbacks and get
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file