piko_transaction 3.0.0 → 3.0.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1576d38fce4625c421d0285b2448092bce7eb73e
|
4
|
+
data.tar.gz: 1501f8f4072e9cf41b562876c70ffbadffc403d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66673e9a68a8aea8aaf476b739962622a5aaa835c7fe96f9e67eb343117ab7cca64b5fa64642bea2e4005ddda44c1e18bf636cbfbbd0059af1290df43abf12bc
|
7
|
+
data.tar.gz: b4e7b4296c20c517f707b53c19a9b818216f69911db52e506a139d799207f972d1aad8b11d42b8c7feefc1c708d76e0017a66c52a37fbe91614783d8d599ae05
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2017 Szymon Kopciewski
|
4
|
+
#
|
5
|
+
# This file is part of PikoTransaction.
|
6
|
+
#
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU General Public License
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
require "piko_transaction/logger"
|
21
|
+
|
22
|
+
module PikoTransaction
|
23
|
+
class Command
|
24
|
+
include Logger
|
25
|
+
|
26
|
+
def initialize()
|
27
|
+
@name = nil
|
28
|
+
@success_callbacks = []
|
29
|
+
@failure_callbacks = []
|
30
|
+
@done = false
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
format "[%s]", @name || self.class.name.split("::").last
|
35
|
+
end
|
36
|
+
|
37
|
+
def name(value)
|
38
|
+
@name = value.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_success_callback(callback)
|
42
|
+
@success_callbacks << callback if callback.respond_to?(:call)
|
43
|
+
logger.debug { format "%s Registered success callbacks: %i", to_s, @success_callbacks.count }
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_failure_callback(callback)
|
47
|
+
@failure_callbacks << callback if callback.respond_to?(:call)
|
48
|
+
logger.debug { format "%s Registered failure callbacks: %i", to_s, @failure_callbacks.count }
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def terminate(msg)
|
54
|
+
logger.warn { format "%s %s", to_s, msg }
|
55
|
+
false
|
56
|
+
end
|
57
|
+
|
58
|
+
def mark_as_done
|
59
|
+
@done = true
|
60
|
+
end
|
61
|
+
|
62
|
+
def mark_as_undone
|
63
|
+
@done = false
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
def can_do?
|
68
|
+
!@done
|
69
|
+
end
|
70
|
+
|
71
|
+
def can_undo?
|
72
|
+
@done
|
73
|
+
end
|
74
|
+
|
75
|
+
def call_failure_callbacks
|
76
|
+
@failure_callbacks.each_with_index do |callback, i|
|
77
|
+
logger.debug { format "%s Run %i failure callback", to_s, i + 1 }
|
78
|
+
callback.call
|
79
|
+
end
|
80
|
+
false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -17,19 +17,14 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require "piko_transaction/
|
20
|
+
require "piko_transaction/command"
|
21
21
|
|
22
22
|
module PikoTransaction
|
23
|
-
class CustomCommand
|
24
|
-
include Logger
|
25
|
-
|
23
|
+
class CustomCommand < Command
|
26
24
|
def initialize(do_action = nil, undo_action = nil, &alternative_do_action)
|
27
|
-
|
25
|
+
super()
|
28
26
|
@do_action = choose_do_action(do_action, alternative_do_action)
|
29
27
|
@undo_action = undo_action
|
30
|
-
@success_callbacks = []
|
31
|
-
@failure_callbacks = []
|
32
|
-
@done = false
|
33
28
|
end
|
34
29
|
|
35
30
|
def do
|
@@ -40,52 +35,12 @@ module PikoTransaction
|
|
40
35
|
execute_undo_action
|
41
36
|
end
|
42
37
|
|
43
|
-
def to_s
|
44
|
-
format "[%s]", @name || "custom_cmd"
|
45
|
-
end
|
46
|
-
|
47
|
-
def name(value)
|
48
|
-
@name = value.to_s
|
49
|
-
end
|
50
|
-
|
51
|
-
def add_success_callback(callback)
|
52
|
-
@success_callbacks << callback if callback.respond_to?(:call)
|
53
|
-
logger.debug { format "%s Registered success callbacks: %i", to_s, @success_callbacks.count }
|
54
|
-
end
|
55
|
-
|
56
|
-
def add_failure_callback(callback)
|
57
|
-
@failure_callbacks << callback if callback.respond_to?(:call)
|
58
|
-
logger.debug { format "%s Registered failure callbacks: %i", to_s, @failure_callbacks.count }
|
59
|
-
end
|
60
|
-
|
61
38
|
private
|
62
39
|
|
63
40
|
def choose_do_action(action, alternative_action)
|
64
41
|
action || alternative_action
|
65
42
|
end
|
66
43
|
|
67
|
-
def terminate(msg)
|
68
|
-
logger.warn { format "%s %s", to_s, msg }
|
69
|
-
false
|
70
|
-
end
|
71
|
-
|
72
|
-
def mark_as_done
|
73
|
-
@done = true
|
74
|
-
end
|
75
|
-
|
76
|
-
def mark_as_undone
|
77
|
-
@done = false
|
78
|
-
true
|
79
|
-
end
|
80
|
-
|
81
|
-
def can_do?
|
82
|
-
!@done
|
83
|
-
end
|
84
|
-
|
85
|
-
def can_undo?
|
86
|
-
@done
|
87
|
-
end
|
88
|
-
|
89
44
|
def execute_do_action
|
90
45
|
return terminate("Command already done") unless can_do?
|
91
46
|
return terminate("'Do' action do not responds to :call") unless \
|
@@ -134,13 +89,5 @@ module PikoTransaction
|
|
134
89
|
end
|
135
90
|
true
|
136
91
|
end
|
137
|
-
|
138
|
-
def call_failure_callbacks
|
139
|
-
@failure_callbacks.each_with_index do |callback, i|
|
140
|
-
logger.debug { format "%s Run %i failure callback", to_s, i + 1 }
|
141
|
-
callback.call
|
142
|
-
end
|
143
|
-
false
|
144
|
-
end
|
145
92
|
end
|
146
93
|
end
|
@@ -17,21 +17,16 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require "piko_transaction/
|
20
|
+
require "piko_transaction/command"
|
21
21
|
|
22
22
|
module PikoTransaction
|
23
|
-
class DeleteCommand
|
24
|
-
include Logger
|
25
|
-
|
23
|
+
class DeleteCommand < Command
|
26
24
|
def initialize(document_id, collection, &success_action)
|
27
|
-
|
25
|
+
super()
|
28
26
|
@document_id = document_id
|
29
27
|
@collection = collection
|
30
28
|
@success_action = success_action
|
31
|
-
@success_callbacks = []
|
32
|
-
@failure_callbacks = []
|
33
29
|
@deleted_doc = nil
|
34
|
-
@done = false
|
35
30
|
end
|
36
31
|
|
37
32
|
def do
|
@@ -43,48 +38,8 @@ module PikoTransaction
|
|
43
38
|
store_document
|
44
39
|
end
|
45
40
|
|
46
|
-
def to_s
|
47
|
-
format "[%s]", @name || "delete_cmd"
|
48
|
-
end
|
49
|
-
|
50
|
-
def name(value)
|
51
|
-
@name = value.to_s
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_success_callback(callback)
|
55
|
-
@success_callbacks << callback if callback.respond_to?(:call)
|
56
|
-
logger.debug { format "%s Registered success callbacks: %s", to_s, @success_callbacks.count }
|
57
|
-
end
|
58
|
-
|
59
|
-
def add_failure_callback(callback)
|
60
|
-
@failure_callbacks << callback if callback.respond_to?(:call)
|
61
|
-
logger.debug { format "%s Registered failure callbacks: %s", to_s, @failure_callbacks.count }
|
62
|
-
end
|
63
|
-
|
64
41
|
private
|
65
42
|
|
66
|
-
def terminate(msg)
|
67
|
-
logger.warn { format "%s %s", to_s, msg }
|
68
|
-
false
|
69
|
-
end
|
70
|
-
|
71
|
-
def mark_as_done
|
72
|
-
@done = true
|
73
|
-
end
|
74
|
-
|
75
|
-
def mark_as_undone
|
76
|
-
@done = false
|
77
|
-
true
|
78
|
-
end
|
79
|
-
|
80
|
-
def can_do?
|
81
|
-
!@done
|
82
|
-
end
|
83
|
-
|
84
|
-
def can_undo?
|
85
|
-
@done
|
86
|
-
end
|
87
|
-
|
88
43
|
def remove_document
|
89
44
|
return terminate("Command already done") unless can_do?
|
90
45
|
return terminate("Error during deleting document") unless delete_document_from_collection
|
@@ -116,13 +71,5 @@ module PikoTransaction
|
|
116
71
|
end
|
117
72
|
true
|
118
73
|
end
|
119
|
-
|
120
|
-
def call_failure_callbacks
|
121
|
-
@failure_callbacks.each_with_index do |callback, i|
|
122
|
-
logger.debug { format "%s Run %i failure callback", to_s, i + 1 }
|
123
|
-
callback.call
|
124
|
-
end
|
125
|
-
false
|
126
|
-
end
|
127
74
|
end
|
128
75
|
end
|
@@ -17,21 +17,16 @@
|
|
17
17
|
# You should have received a copy of the GNU General Public License
|
18
18
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
require "piko_transaction/
|
20
|
+
require "piko_transaction/command"
|
21
21
|
|
22
22
|
module PikoTransaction
|
23
|
-
class InsertCommand
|
24
|
-
include Logger
|
25
|
-
|
23
|
+
class InsertCommand < Command
|
26
24
|
def initialize(document, collection, &success_action)
|
27
|
-
|
25
|
+
super()
|
28
26
|
@document = document
|
29
27
|
@collection = collection
|
30
28
|
@success_action = success_action
|
31
|
-
@success_callbacks = []
|
32
|
-
@failure_callbacks = []
|
33
29
|
@inserted_id = nil
|
34
|
-
@done = false
|
35
30
|
end
|
36
31
|
|
37
32
|
def do
|
@@ -43,48 +38,8 @@ module PikoTransaction
|
|
43
38
|
remove_document
|
44
39
|
end
|
45
40
|
|
46
|
-
def to_s
|
47
|
-
format "[%s]", @name || "insert_cmd"
|
48
|
-
end
|
49
|
-
|
50
|
-
def name(value)
|
51
|
-
@name = value.to_s
|
52
|
-
end
|
53
|
-
|
54
|
-
def add_success_callback(callback)
|
55
|
-
@success_callbacks << callback if callback.respond_to?(:call)
|
56
|
-
logger.debug { format "%s Registered success callbacks: %i", to_s, @success_callbacks.count }
|
57
|
-
end
|
58
|
-
|
59
|
-
def add_failure_callback(callback)
|
60
|
-
@failure_callbacks << callback if callback.respond_to?(:call)
|
61
|
-
logger.debug { format "%s Registered failure callbacks: %i", to_s, @failure_callbacks.count }
|
62
|
-
end
|
63
|
-
|
64
41
|
private
|
65
42
|
|
66
|
-
def terminate(msg)
|
67
|
-
logger.warn { format "%s %s", to_s, msg }
|
68
|
-
false
|
69
|
-
end
|
70
|
-
|
71
|
-
def mark_as_done
|
72
|
-
@done = true
|
73
|
-
end
|
74
|
-
|
75
|
-
def mark_as_undone
|
76
|
-
@done = false
|
77
|
-
true
|
78
|
-
end
|
79
|
-
|
80
|
-
def can_do?
|
81
|
-
!@done
|
82
|
-
end
|
83
|
-
|
84
|
-
def can_undo?
|
85
|
-
@done
|
86
|
-
end
|
87
|
-
|
88
43
|
def store_document
|
89
44
|
return terminate("Command already done") unless can_do?
|
90
45
|
return terminate("Error during inserting document") unless insert_document_into_collection
|
@@ -116,13 +71,5 @@ module PikoTransaction
|
|
116
71
|
end
|
117
72
|
true
|
118
73
|
end
|
119
|
-
|
120
|
-
def call_failure_callbacks
|
121
|
-
@failure_callbacks.each_with_index do |callback, i|
|
122
|
-
logger.debug { format "%s Run %i failure callback", to_s, i + 1 }
|
123
|
-
callback.call
|
124
|
-
end
|
125
|
-
false
|
126
|
-
end
|
127
74
|
end
|
128
75
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piko_transaction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Szymon Kopciewski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logger2r
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- LICENSE
|
121
121
|
- README.md
|
122
122
|
- lib/piko_transaction.rb
|
123
|
+
- lib/piko_transaction/command.rb
|
123
124
|
- lib/piko_transaction/custom_command.rb
|
124
125
|
- lib/piko_transaction/delete_command.rb
|
125
126
|
- lib/piko_transaction/insert_command.rb
|
@@ -147,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
150
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
151
|
+
rubygems_version: 2.6.12
|
151
152
|
signing_key:
|
152
153
|
specification_version: 4
|
153
154
|
summary: Abstraction layer for storage
|