actionizer 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/.travis.yml +2 -2
- data/lib/actionizer/version.rb +1 -1
- data/lib/actionizer.rb +12 -34
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4ba43f3da535184ec6366336270f8d0777d6860
|
4
|
+
data.tar.gz: 2c52d1f362aab8b9219f0e18b81dbf1bd0a6155a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0dc88d7ec0218df10165d77703ff278753e9dd4051daa8bfe6137a4f7204e044fd04aa1d90928ae3cebd8ef77c66faf4cf194571cd3ca05e1d3a523a826e56
|
7
|
+
data.tar.gz: 1176e8feea9c760a88d04c54b20e58bcf379745ffd880a97b9593eac8099f15341a9f682da5667e6c8fcc1d8f64b54ebbbb27f57ad0e6862ba6639a68fa6f04c
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
data/lib/actionizer/version.rb
CHANGED
data/lib/actionizer.rb
CHANGED
@@ -6,6 +6,7 @@ require 'actionizer/inputs'
|
|
6
6
|
|
7
7
|
module Actionizer
|
8
8
|
attr_reader :input, :output
|
9
|
+
attr_accessor :raise_on_failure
|
9
10
|
|
10
11
|
def self.included(base)
|
11
12
|
base.extend(ClassMethods)
|
@@ -15,10 +16,15 @@ module Actionizer
|
|
15
16
|
def method_missing(method_name, *args, &block)
|
16
17
|
instance = new(*args)
|
17
18
|
|
19
|
+
if method_name.to_s.end_with?('!')
|
20
|
+
method_name = method_name.to_s.chomp('!').to_sym
|
21
|
+
instance.raise_on_failure = true
|
22
|
+
end
|
23
|
+
|
18
24
|
if instance.respond_to?(method_name)
|
19
25
|
error = defined_inputs.check_for_param_error(method_name, *args)
|
20
26
|
if error
|
21
|
-
|
27
|
+
raise Actionizer::Failure.new('Failed.', Actionizer::Result.new(error: error).tap(&:fail))
|
22
28
|
end
|
23
29
|
|
24
30
|
instance.tap(&method_name).output
|
@@ -26,6 +32,10 @@ module Actionizer
|
|
26
32
|
super
|
27
33
|
end
|
28
34
|
rescue Actionizer::Failure => af
|
35
|
+
if instance.raise_on_failure
|
36
|
+
raise af
|
37
|
+
end
|
38
|
+
|
29
39
|
af.output
|
30
40
|
end
|
31
41
|
|
@@ -69,6 +79,7 @@ module Actionizer
|
|
69
79
|
def initialize(initial_input = {})
|
70
80
|
@input = OpenStruct.new(initial_input)
|
71
81
|
@output = Actionizer::Result.new
|
82
|
+
@raise_on_failure = false
|
72
83
|
end
|
73
84
|
|
74
85
|
def fail!(params = {})
|
@@ -78,37 +89,4 @@ module Actionizer
|
|
78
89
|
|
79
90
|
raise Actionizer::Failure.new('Failed!', output)
|
80
91
|
end
|
81
|
-
|
82
|
-
# Allows you to call *_or_fail
|
83
|
-
def method_missing(method_name, *args, &block)
|
84
|
-
return super if !method_name.to_s.end_with?('_or_fail')
|
85
|
-
|
86
|
-
action_class, *params = args
|
87
|
-
underlying_method = method_name.to_s.chomp('_or_fail')
|
88
|
-
|
89
|
-
if !action_class.respond_to?(underlying_method)
|
90
|
-
raise ArgumentError, "#{action_class.name} must define ##{underlying_method}"
|
91
|
-
end
|
92
|
-
|
93
|
-
result = action_class.send(underlying_method, *params)
|
94
|
-
|
95
|
-
verify_result_is_conforming!(result, "#{action_class.name}##{underlying_method}")
|
96
|
-
|
97
|
-
errors = result.to_h.select { |key, _value| key.to_s.start_with?('error') }
|
98
|
-
fail!(errors) if result.failure?
|
99
|
-
|
100
|
-
result
|
101
|
-
end
|
102
|
-
|
103
|
-
def respond_to_missing?(method_name, _include_private = false)
|
104
|
-
method_name.to_s.end_with?('_or_fail')
|
105
|
-
end
|
106
|
-
|
107
|
-
private
|
108
|
-
|
109
|
-
def verify_result_is_conforming!(result, class_and_method)
|
110
|
-
raise ArgumentError, "#{class_and_method}'s result must respond to :to_h" if !result.respond_to?(:to_h)
|
111
|
-
|
112
|
-
raise ArgumentError, "#{class_and_method}'s result must respond to :failure?" if !result.respond_to?(:failure?)
|
113
|
-
end
|
114
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: actionizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Nichols
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
158
|
+
rubygems_version: 2.6.11
|
159
159
|
signing_key:
|
160
160
|
specification_version: 4
|
161
161
|
summary: Turn your classes into small, modular, reusable Actions
|