subroutine 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/subroutine/op.rb +21 -14
- data/lib/subroutine/version.rb +2 -2
- data/test/subroutine/base_test.rb +5 -0
- data/test/support/ops.rb +7 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adec63683815f30335f67edb81ae73e313cf7046
|
4
|
+
data.tar.gz: 07726344ba242224d384a4ad6c38af2f9985cddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cfbdb1c872febd5ed53e2d6ef3466faf32fb20e02cfb4a8485c8c8e0f528ddfd3b10671063a22c173c6c81409337fd1e4f29fe218f5ae3e8797231108f207c5
|
7
|
+
data.tar.gz: 048c5ad5a14f44aba3f8bfedbdb02ed8617e7d6ffe92656b8a7f99140eda49d0216aac64f368da7182f9fd7a0ed515f6062a57af23ab6b9049a49d18a315bae2
|
data/lib/subroutine/op.rb
CHANGED
@@ -180,35 +180,42 @@ module Subroutine
|
|
180
180
|
end
|
181
181
|
|
182
182
|
def submit!
|
183
|
-
unless submit
|
184
|
-
raise ::Subroutine::Failure.new(self)
|
185
|
-
end
|
186
|
-
true
|
187
|
-
end
|
188
183
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
184
|
+
begin
|
185
|
+
observe_submission do
|
186
|
+
validate_and_perform
|
187
|
+
end
|
188
|
+
rescue Exception => e
|
189
|
+
if e.respond_to?(:record)
|
190
|
+
inherit_errors(e.record) unless e.record == self
|
191
|
+
raise ::Subroutine::Failure.new(self)
|
192
|
+
else
|
193
|
+
raise
|
194
|
+
end
|
193
195
|
end
|
194
196
|
|
195
|
-
if
|
197
|
+
if errors.empty?
|
196
198
|
_outputs.each_pair do |name, config|
|
197
199
|
if config[:required] && !@outputs.key?(name)
|
198
200
|
raise ::Subroutine::OutputNotSetError.new(name)
|
199
201
|
end
|
200
202
|
end
|
201
|
-
end
|
202
203
|
|
203
|
-
|
204
|
+
true
|
205
|
+
else
|
206
|
+
raise ::Subroutine::Failure.new(self)
|
207
|
+
end
|
208
|
+
end
|
204
209
|
|
210
|
+
# the action which should be invoked upon form submission (from the controller)
|
211
|
+
def submit
|
212
|
+
submit!
|
205
213
|
rescue Exception => e
|
206
|
-
|
207
214
|
if e.respond_to?(:record)
|
208
215
|
inherit_errors(e.record) unless e.record == self
|
209
216
|
false
|
210
217
|
else
|
211
|
-
raise
|
218
|
+
raise
|
212
219
|
end
|
213
220
|
end
|
214
221
|
|
data/lib/subroutine/version.rb
CHANGED
@@ -119,6 +119,11 @@ module Subroutine
|
|
119
119
|
assert_equal "Password can't be blank", err.message
|
120
120
|
end
|
121
121
|
|
122
|
+
def test_the_result_of_perform_doesnt_matter
|
123
|
+
op = ::FalsePerformOp.new
|
124
|
+
assert op.submit!
|
125
|
+
end
|
126
|
+
|
122
127
|
def test_it_allows_submission_from_the_class
|
123
128
|
op = SignupOp.submit
|
124
129
|
assert_equal ["can't be blank"], op.errors[:email]
|
data/test/support/ops.rb
CHANGED
@@ -201,6 +201,12 @@ class InheritedPolymorphicAssociationOp < ::Subroutine::Op
|
|
201
201
|
inputs_from PolymorphicAssociationOp
|
202
202
|
end
|
203
203
|
|
204
|
+
class FalsePerformOp < ::Subroutine::Op
|
205
|
+
def perform
|
206
|
+
false
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
204
210
|
class MissingOutputOp < ::Subroutine::Op
|
205
211
|
def perform
|
206
212
|
output :foo, "bar"
|
@@ -224,6 +230,6 @@ end
|
|
224
230
|
class NoOutputNoSuccessOp < ::Subroutine::Op
|
225
231
|
outputs :foo
|
226
232
|
def perform
|
227
|
-
|
233
|
+
errors.add(:foo, "bar")
|
228
234
|
end
|
229
235
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subroutine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|