fish_transactions 1.0.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +51 -5
- data/lib/fish_transactions.rb +59 -0
- data/lib/fish_transactions/callbacks.rb +42 -0
- data/lib/fish_transactions/version.rb +1 -1
- data/spec/fish_transactions_spec.rb +23 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f0a193af2c3034dd8fa7ab67272b97727bdd31f0
|
4
|
+
data.tar.gz: 3395ae0c828efdd6cf412672f9c85af768936c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1662a9bfff22ef3ff8e378be5a545c97e7317a94d9b2b72368e303f28b8204051e93fe8a042e6472450e3bd5ee3f24987c94faf30e9890de5554d0904cecb923
|
7
|
+
data.tar.gz: 3a9ae0856c07daafadb09c6b2dbb608671bf9cddeeb4ca96ad4f4e808839bf9f4ef0470fa0f448cddb0dce79e07b9157822c28e3ae6daf5561fee7f706c9de4d
|
data/README.md
CHANGED
@@ -31,7 +31,7 @@ the code you wanna run on such events.
|
|
31
31
|
```ruby
|
32
32
|
class SomeClass
|
33
33
|
|
34
|
-
include
|
34
|
+
include FishTransactions::Callbacks
|
35
35
|
|
36
36
|
# ...
|
37
37
|
|
@@ -44,8 +44,8 @@ class SomeClass
|
|
44
44
|
|
45
45
|
after_commit do
|
46
46
|
|
47
|
-
# things to do after
|
48
|
-
puts "runs after
|
47
|
+
# things to do after commit
|
48
|
+
puts "runs after commit"
|
49
49
|
|
50
50
|
end
|
51
51
|
|
@@ -65,10 +65,56 @@ will output
|
|
65
65
|
```
|
66
66
|
runs within transaction
|
67
67
|
again runs within transaction
|
68
|
-
runs after
|
68
|
+
runs after commit
|
69
|
+
```
|
70
|
+
|
71
|
+
Please see `FishTransactions::Callbacks` for more details.
|
72
|
+
|
73
|
+
## Alternative class methods usage
|
74
|
+
Since 1.1 version you can also directly use `after_* methods` as FishTransactions class methods.
|
75
|
+
|
76
|
+
|
77
|
+
#### Example
|
78
|
+
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
class SomeClass
|
82
|
+
|
83
|
+
# ...
|
84
|
+
|
85
|
+
def some_method
|
86
|
+
# ...
|
87
|
+
|
88
|
+
ActiveRecord::Base.transaction do
|
89
|
+
# executes some code
|
90
|
+
puts "runs within transaction"
|
91
|
+
|
92
|
+
FishTransactions.after_commit do
|
93
|
+
|
94
|
+
# things to do after commit
|
95
|
+
puts "runs after commit"
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
# executes more code
|
100
|
+
puts "again runs within transaction"
|
101
|
+
end
|
102
|
+
# ...
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
# ...
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
```
|
111
|
+
will output
|
112
|
+
```
|
113
|
+
runs within transaction
|
114
|
+
again runs within transaction
|
115
|
+
runs after commit
|
69
116
|
```
|
70
117
|
|
71
|
-
Please see [FishTransactions::Callbacks](FishTransactions/Callbacks.html) for more details.
|
72
118
|
|
73
119
|
## Contributing
|
74
120
|
|
data/lib/fish_transactions.rb
CHANGED
@@ -2,3 +2,62 @@ require 'fish_transactions/version'
|
|
2
2
|
require 'fish_transactions/active_record_mods'
|
3
3
|
require 'fish_transactions/callbacks'
|
4
4
|
|
5
|
+
##
|
6
|
+
# FishTransactions is the main Module which includes
|
7
|
+
# all fish transaction features.
|
8
|
+
#
|
9
|
+
# Please visit FishTransactions::Callbacks for more information of how to use these callbacks
|
10
|
+
#
|
11
|
+
# Example of usage:
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# class SomeClass
|
15
|
+
#
|
16
|
+
# include FishTransactions::Callbacks
|
17
|
+
#
|
18
|
+
# # ...
|
19
|
+
#
|
20
|
+
# def some_method
|
21
|
+
# # ...
|
22
|
+
#
|
23
|
+
# ActiveRecord::Base.transaction do
|
24
|
+
# # executes some code
|
25
|
+
# puts "runs within transaction"
|
26
|
+
#
|
27
|
+
# after_commit do
|
28
|
+
#
|
29
|
+
# # things to do after commit
|
30
|
+
# puts "runs after commit"
|
31
|
+
#
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # executes more code
|
35
|
+
# puts "again runs within transaction"
|
36
|
+
# end
|
37
|
+
# # ...
|
38
|
+
#
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # ...
|
42
|
+
#
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
#
|
46
|
+
# will output
|
47
|
+
#
|
48
|
+
# runs within transaction
|
49
|
+
# again runs within transaction
|
50
|
+
# runs after commit
|
51
|
+
#
|
52
|
+
# Optionally, you can use callbacks as
|
53
|
+
# FishTransactions class methods, like this:
|
54
|
+
#
|
55
|
+
# FishTransactions.after_commit do
|
56
|
+
# # thinks to do after commit
|
57
|
+
# end
|
58
|
+
#
|
59
|
+
# <b>Please prefer including FishTransactions::Callbacks on your classes before using class methods style.</b>
|
60
|
+
#
|
61
|
+
module FishTransactions
|
62
|
+
extend FishTransactions::Callbacks
|
63
|
+
end
|
@@ -7,6 +7,48 @@ module FishTransactions
|
|
7
7
|
# You just need to include this module and you will able to
|
8
8
|
# use it.
|
9
9
|
#
|
10
|
+
#
|
11
|
+
# Example of usage:
|
12
|
+
#
|
13
|
+
#
|
14
|
+
# class SomeClass
|
15
|
+
#
|
16
|
+
# include FishTransactions::Callbacks
|
17
|
+
#
|
18
|
+
# # ...
|
19
|
+
#
|
20
|
+
# def some_method
|
21
|
+
# # ...
|
22
|
+
#
|
23
|
+
# ActiveRecord::Base.transaction do
|
24
|
+
# # executes some code
|
25
|
+
# puts "runs within transaction"
|
26
|
+
#
|
27
|
+
# after_commit do
|
28
|
+
#
|
29
|
+
# # things to do after commit
|
30
|
+
# puts "runs after commit"
|
31
|
+
#
|
32
|
+
# end
|
33
|
+
#
|
34
|
+
# # executes more code
|
35
|
+
# puts "again runs within transaction"
|
36
|
+
# end
|
37
|
+
# # ...
|
38
|
+
#
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# # ...
|
42
|
+
#
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
#
|
46
|
+
# will output
|
47
|
+
#
|
48
|
+
# runs within transaction
|
49
|
+
# again runs within transaction
|
50
|
+
# runs after commit
|
51
|
+
#
|
10
52
|
module Callbacks
|
11
53
|
|
12
54
|
##
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fish_transactions'
|
2
|
+
|
3
|
+
describe FishTransactions do
|
4
|
+
|
5
|
+
describe '.after_transaction' do
|
6
|
+
it 'should exists' do
|
7
|
+
expect(FishTransactions).to respond_to(:after_transaction)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '.after_commit' do
|
12
|
+
it 'should exists' do
|
13
|
+
expect(FishTransactions).to respond_to(:after_commit)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.after_rollback' do
|
18
|
+
it 'should exists' do
|
19
|
+
expect(FishTransactions).to respond_to(:after_rollback)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fish_transactions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.1'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Owen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/fish_transactions/version.rb
|
129
129
|
- spec/callbacks_spec.rb
|
130
130
|
- spec/callbacks_storage_spec.rb
|
131
|
+
- spec/fish_transactions_spec.rb
|
131
132
|
- spec/spec_helper.rb
|
132
133
|
homepage: https://github.com/Beetrack/fish_transactions
|
133
134
|
licenses:
|
@@ -156,4 +157,5 @@ summary: Callbacks for Active Record transactions that can be used anywhere.
|
|
156
157
|
test_files:
|
157
158
|
- spec/callbacks_spec.rb
|
158
159
|
- spec/callbacks_storage_spec.rb
|
160
|
+
- spec/fish_transactions_spec.rb
|
159
161
|
- spec/spec_helper.rb
|