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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc8cb9dc7e92353478947c8c9a88c166b5c02061
4
- data.tar.gz: b612897d0b21304de584ea98a3801d6e7a76ea35
3
+ metadata.gz: 57083b19aff05a44248885c7590c6a7de5cfa621
4
+ data.tar.gz: c9508b343566892827858014891be2bb855e4231
5
5
  SHA512:
6
- metadata.gz: 25b5ef8875fb3de5cf84bc7d1ae856c1345cae080deef13a3d04442be5106154aaf915b3682846876323b5fd229ecbe81002d5653637be037d98a198f10dc057
7
- data.tar.gz: e60ebe4a9de753d450a408b00302771c333e044df90d76c6305ced6d9a8b46a9303ede4086456a55afc5a3ba91c0d907d923bcc241df986f487e0ba8b13cc31d
6
+ metadata.gz: 948506f91923b06f1a64fd9840b6ca5789cc710ab39c48d0642930605aacb351991532cee120aed72a6983cb7ebac7ec7de5baf139fa3fd609a39192396f763a
7
+ data.tar.gz: 0661def7d1be979008dddd435fc2cd3b489329473d28ee92497d4588e1d622f84471e3c94b731f952f57d93f9b627a8666fb65428f530fef49a53ce56b17dc39
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.0
@@ -73,8 +73,8 @@ module ExMachina
73
73
  runner = Execution.new(self, transition)
74
74
  runner.run
75
75
 
76
- result = runner.success?
77
- break result unless runner.skipped?
76
+ result = runner.current
77
+ break if runner.success?
78
78
  end
79
79
  end
80
80
  result
@@ -28,7 +28,7 @@ module ExMachina
28
28
  @running = true
29
29
  @result = nil
30
30
  @previous = event.status
31
- @current = nil
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 = @previous
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
- # TODO handle exception
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
- call = invoke(:perform)
107
- invoke(transition.do_after)
108
- finish!(call)
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(:transit)
115
- invoke(transition.do_success)
118
+ invoke(callback(:success))
116
119
  elsif failure?
117
- invoke(transition.do_failure)
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
- call
129
+ performed
121
130
  end
122
131
 
123
132
  protected
124
133
 
125
- def invoke(meth, arg = self)
126
- Util.invoke_method(event, meth, arg)
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)
@@ -1,3 +1,3 @@
1
1
  module ExMachina
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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.2
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-03-06 00:00:00.000000000 Z
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