comandor 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e1a9b95cb03bfabc30c1b129dbbd599081a42f22
4
- data.tar.gz: 9be6713941da916d71aea0fc52184e3591b62c42
3
+ metadata.gz: 2e8d00a4c66e2d46005ab21115cf2da4e14e16e3
4
+ data.tar.gz: db387784f792404b6063c85319bf1ddf528dc6a1
5
5
  SHA512:
6
- metadata.gz: 30e07511edbde805c5691f37c12f6a7a94512fb6f3b19b038624f0d0cc668eaeda32583860692c819157d0c8d220e7f57340f1d993d410a4ba49dd4f50024e22
7
- data.tar.gz: e300aa36c40273a92f35d8d5c0ea4b1746e0295b51c791777622a04fd79289b5760b0249feed9a5470edacdc9186b6cf7a0c27854f8f133c73af1476ee7e679c
6
+ metadata.gz: 8f4ed9df50116f37214b853b9722a9d68521182bba5c7df130d4629505d13ef4134b18946eff26a99b55602fb5aba91ab1939c78af7bfbcbf0e7483077ee2511
7
+ data.tar.gz: 97a1ce2e6f1ee46f465d350b1768ef1e4d03b9e3a2e9aeda0490d3a9199ed8c07fcf8845dad9c4c01cbdc7eec0e02fdb9b122cbb5fbc446f24ddd40f82900f72
data/README.md CHANGED
@@ -172,6 +172,22 @@ example of using:
172
172
  end
173
173
  ```
174
174
 
175
+ `transaction!` wrapper around `perform` method look like
176
+ ```ruby
177
+ class User::Message
178
+ extend Comandor
179
+ transaction! 'ActiveRecord::Base.transaction'
180
+
181
+ def perform(user)
182
+ @user = user
183
+ create_message! && send_message! && write_log! &&
184
+ end
185
+ #...
186
+ end
187
+
188
+ User::Message.perform(User.first)
189
+ ```
190
+
175
191
  ## Development
176
192
 
177
193
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -17,12 +17,33 @@ module Comandor
17
17
  def perform(*args, &block)
18
18
  new.perform(*args, &block)
19
19
  end
20
+
21
+ # Add transaction layer
22
+ # @param [name] [String] ActiveRecord::Base.transaction
23
+ def transaction!(name)
24
+ class_eval { @transaction_klass, @transaction_method = name.split('.') }
25
+ end
26
+
27
+ # Class variables accessor
28
+ def transaction_klass
29
+ @transaction_klass
30
+ end
31
+
32
+ def transaction_method
33
+ @transaction_method
34
+ end
20
35
  end
21
36
 
22
37
  # @return [self]
23
38
  def perform(*args, &block)
24
39
  raise NoMethodError unless defined?(:perform)
25
- @result = super
40
+ if self.class.transaction_klass && self.class.transaction_method
41
+ @result = Object.const_get(self.class.transaction_klass).send self.class.transaction_method.to_sym do
42
+ super
43
+ end
44
+ else
45
+ @result = super
46
+ end
26
47
  @done = true
27
48
  self
28
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Comandor
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comandor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Renat "MpaK" Ibragimov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-03 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler