operation 1.3.2 → 1.4.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/operation/deferrable.rb +49 -7
- data/lib/operation/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c5ab2af692001edf354b6c55769c944e0d6b305
|
4
|
+
data.tar.gz: 6e90ab32338fe7d2ee8b5c2587cb5f80366fcda3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a82fdaddecfd11cc0807048b908ac4ca11af4c03ee48033d43c6083f30329a8d0d815bb51085154d5913313bf69c93e73c7692b99081ca18e09acb23c9d7694d
|
7
|
+
data.tar.gz: f2656a9c0e58277130dcf18fe48e8e2e0d1008dffedc26a106ae448944d5746025dda1ede2e31d649289b50bd78d711d760cb6374c3555c0010588a70979ef94
|
data/lib/operation/deferrable.rb
CHANGED
@@ -4,6 +4,17 @@ class Operation
|
|
4
4
|
|
5
5
|
# Public Callbacks
|
6
6
|
|
7
|
+
def on_start(&block)
|
8
|
+
return unless block
|
9
|
+
|
10
|
+
if started?
|
11
|
+
block.call
|
12
|
+
else
|
13
|
+
startables.unshift block
|
14
|
+
end
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
7
18
|
def on_progress(&block)
|
8
19
|
return unless block
|
9
20
|
progressables.unshift block
|
@@ -36,7 +47,7 @@ class Operation
|
|
36
47
|
return unless block
|
37
48
|
|
38
49
|
if succeeded? || failed?
|
39
|
-
block.call
|
50
|
+
block.call
|
40
51
|
else
|
41
52
|
finishables.unshift block
|
42
53
|
end
|
@@ -62,16 +73,22 @@ class Operation
|
|
62
73
|
status == :failed
|
63
74
|
end
|
64
75
|
|
76
|
+
def started?
|
77
|
+
status != :unknown
|
78
|
+
end
|
79
|
+
|
65
80
|
# Public State Setters
|
66
81
|
|
67
82
|
def progress!(new_percent, code = nil)
|
68
83
|
return if succeeded? || failed?
|
69
84
|
@percent = new_percent.to_i
|
85
|
+
start! unless started?
|
70
86
|
@status = code unless [:succeeded, :failed].include?(code)
|
71
87
|
|
72
88
|
progressables.each do |callback|
|
73
89
|
callback.call self
|
74
90
|
end
|
91
|
+
self
|
75
92
|
end
|
76
93
|
|
77
94
|
def sub_progress!(from, till, sub)
|
@@ -82,6 +99,11 @@ class Operation
|
|
82
99
|
new_percent = from.to_i + factor.to_i
|
83
100
|
end
|
84
101
|
progress! new_percent, sub.status
|
102
|
+
self
|
103
|
+
end
|
104
|
+
|
105
|
+
def start!(*args)
|
106
|
+
set_status :started, *args
|
85
107
|
end
|
86
108
|
|
87
109
|
def succeed!(*args)
|
@@ -98,28 +120,48 @@ class Operation
|
|
98
120
|
@arguments = args unless args.empty?
|
99
121
|
@status = new_status
|
100
122
|
|
123
|
+
call_startables!
|
101
124
|
if succeeded? && !successables.empty?
|
102
125
|
while callback = successables.pop
|
103
126
|
callback.call(*arguments)
|
104
127
|
end
|
105
|
-
|
106
|
-
callback.call(*arguments)
|
107
|
-
end
|
128
|
+
call_finishables!
|
108
129
|
failables.clear if !failables.empty?
|
109
130
|
|
110
131
|
elsif failed? && !failables.empty?
|
111
132
|
while callback = failables.pop
|
112
133
|
callback.call(*arguments)
|
113
134
|
end
|
114
|
-
|
115
|
-
callback.call(*arguments)
|
116
|
-
end
|
135
|
+
call_finishables!
|
117
136
|
successables.clear if !failables.empty?
|
118
137
|
end
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
141
|
+
def call_startables!
|
142
|
+
return unless startables
|
143
|
+
return if startables.empty?
|
144
|
+
|
145
|
+
while callback = startables.pop
|
146
|
+
callback.call
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def call_finishables!
|
151
|
+
return unless finishables
|
152
|
+
return if finishables.empty?
|
153
|
+
|
154
|
+
while callback = finishables.pop
|
155
|
+
callback.call
|
156
|
+
end
|
119
157
|
end
|
120
158
|
|
121
159
|
# Internal Methods
|
122
160
|
|
161
|
+
def startables
|
162
|
+
@startables ||= []
|
163
|
+
end
|
164
|
+
|
123
165
|
def successables
|
124
166
|
@successables ||= []
|
125
167
|
end
|
data/lib/operation/version.rb
CHANGED