ex_machina 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/lib/ex_machina/event.rb +2 -2
- data/lib/ex_machina/event/execution.rb +31 -15
- data/lib/ex_machina/event/transition.rb +3 -2
- data/lib/ex_machina/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57083b19aff05a44248885c7590c6a7de5cfa621
|
4
|
+
data.tar.gz: c9508b343566892827858014891be2bb855e4231
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 948506f91923b06f1a64fd9840b6ca5789cc710ab39c48d0642930605aacb351991532cee120aed72a6983cb7ebac7ec7de5baf139fa3fd609a39192396f763a
|
7
|
+
data.tar.gz: 0661def7d1be979008dddd435fc2cd3b489329473d28ee92497d4588e1d622f84471e3c94b731f952f57d93f9b627a8666fb65428f530fef49a53ce56b17dc39
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/lib/ex_machina/event.rb
CHANGED
@@ -28,7 +28,7 @@ module ExMachina
|
|
28
28
|
@running = true
|
29
29
|
@result = nil
|
30
30
|
@previous = event.status
|
31
|
-
@current =
|
31
|
+
@current = event.status
|
32
32
|
end
|
33
33
|
|
34
34
|
def finish!(value)
|
@@ -44,7 +44,7 @@ module ExMachina
|
|
44
44
|
elsif value == :skipped
|
45
45
|
skipped!
|
46
46
|
elsif value == :error
|
47
|
-
error!
|
47
|
+
error!(@exception)
|
48
48
|
else
|
49
49
|
@result = value
|
50
50
|
end
|
@@ -65,7 +65,7 @@ module ExMachina
|
|
65
65
|
result == :failure
|
66
66
|
end
|
67
67
|
def failure!
|
68
|
-
@current =
|
68
|
+
@current = previous
|
69
69
|
finish!(@result = :failure)
|
70
70
|
end
|
71
71
|
|
@@ -77,7 +77,7 @@ module ExMachina
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def error!(exception)
|
80
|
-
|
80
|
+
@exception = exception
|
81
81
|
finish!(@result = :error)
|
82
82
|
end
|
83
83
|
def error?
|
@@ -98,32 +98,48 @@ module ExMachina
|
|
98
98
|
|
99
99
|
def run
|
100
100
|
start!
|
101
|
-
|
102
101
|
return skipped! unless eligible?
|
103
102
|
|
104
|
-
invoke(transition.do_before)
|
105
103
|
begin
|
106
|
-
|
107
|
-
invoke(
|
108
|
-
|
104
|
+
invoke(callback(:before), true)
|
105
|
+
if (performed = invoke(:perform, true))
|
106
|
+
success!
|
107
|
+
else
|
108
|
+
failure!
|
109
|
+
end
|
110
|
+
invoke(:transit)
|
111
|
+
invoke(callback(:after))
|
112
|
+
|
109
113
|
rescue StandardError => ex
|
110
114
|
error!(ex)
|
111
115
|
end
|
112
116
|
|
113
117
|
if success?
|
114
|
-
invoke(:
|
115
|
-
invoke(transition.do_success)
|
118
|
+
invoke(callback(:success))
|
116
119
|
elsif failure?
|
117
|
-
invoke(
|
120
|
+
invoke(callback(:failure))
|
121
|
+
elsif error?
|
122
|
+
invoke(callback(:error))
|
123
|
+
elsif skipped?
|
124
|
+
invoke(callback(:skip))
|
125
|
+
else
|
126
|
+
# do what?
|
118
127
|
end
|
119
128
|
|
120
|
-
|
129
|
+
performed
|
121
130
|
end
|
122
131
|
|
123
132
|
protected
|
124
133
|
|
125
|
-
|
126
|
-
|
134
|
+
# return the transition 'do_callback' or default '(before|after)_transition method
|
135
|
+
def callback(name)
|
136
|
+
transition.send("do_#{name}") || "#{name}_#{previous}_to_#{current}"
|
137
|
+
end
|
138
|
+
|
139
|
+
def invoke(meth, default = nil)
|
140
|
+
result = Util.invoke_method(event, meth, self)
|
141
|
+
return default if result.nil?
|
142
|
+
result
|
127
143
|
end
|
128
144
|
end
|
129
145
|
end
|
@@ -3,9 +3,9 @@ module ExMachina
|
|
3
3
|
class Transition
|
4
4
|
|
5
5
|
attr_reader :from, :to
|
6
|
-
attr_reader :do_if, :do_unless, :do_before, :do_after, :do_success, :do_failure
|
6
|
+
attr_reader :do_if, :do_unless, :do_before, :do_after, :do_success, :do_failure, :do_error
|
7
7
|
|
8
|
-
def initialize(options)
|
8
|
+
def initialize(**options)
|
9
9
|
@from = Array(options.fetch(:from)).map { |status| normalize(status) }
|
10
10
|
@to = normalize(options.fetch(:to))
|
11
11
|
|
@@ -16,6 +16,7 @@ module ExMachina
|
|
16
16
|
@do_after = options[:after]
|
17
17
|
@do_success = options[:success]
|
18
18
|
@do_failure = options[:failure]
|
19
|
+
@do_error = options[:error]
|
19
20
|
end
|
20
21
|
|
21
22
|
def from?(status)
|
data/lib/ex_machina/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ex_machina
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Panachi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -61,6 +61,7 @@ extra_rdoc_files: []
|
|
61
61
|
files:
|
62
62
|
- ".gitignore"
|
63
63
|
- ".rspec"
|
64
|
+
- ".ruby-version"
|
64
65
|
- Gemfile
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|