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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f469641ab666e35726b4d5947291460f7ee19d4e
4
- data.tar.gz: a502b47502c021c1d6a727c5a88dea62426d0d1e
3
+ metadata.gz: f4ba43f3da535184ec6366336270f8d0777d6860
4
+ data.tar.gz: 2c52d1f362aab8b9219f0e18b81dbf1bd0a6155a
5
5
  SHA512:
6
- metadata.gz: aa6f99b81e8a95dcb0d58dc02befc7442ffd930c0ff5d119c8b92ec9d91b713da3e972f421443ce8db27f8cbdda3932c2d27d3be2b980b86f71f9d5622581291
7
- data.tar.gz: 84ac0753c80f7759acf0281cd9c9d024058a7d7787c5ddbcb705f4998887c26f020637c7822835792bc7d2942fe28a39c061f5546f99720bafaaa3ec2de73859
6
+ metadata.gz: 3c0dc88d7ec0218df10165d77703ff278753e9dd4051daa8bfe6137a4f7204e044fd04aa1d90928ae3cebd8ef77c66faf4cf194571cd3ca05e1d3a523a826e56
7
+ data.tar.gz: 1176e8feea9c760a88d04c54b20e58bcf379745ffd880a97b9593eac8099f15341a9f682da5667e6c8fcc1d8f64b54ebbbb27f57ad0e6862ba6639a68fa6f04c
data/.rubocop.yml CHANGED
@@ -10,7 +10,7 @@ Metrics/PerceivedComplexity:
10
10
  Metrics/LineLength:
11
11
  Max: 120
12
12
  Metrics/MethodLength:
13
- Max: 15
13
+ Max: 20
14
14
 
15
15
  Style/Documentation:
16
16
  Enabled: false
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.1.0
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.13.6
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
6
6
  script: rubocop -D && bundle exec rspec
7
7
  addons:
8
8
  code_climate:
@@ -1,3 +1,3 @@
1
1
  module Actionizer
2
- VERSION = '0.11.0'
2
+ VERSION = '0.12.0'
3
3
  end
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
- return Actionizer::Result.new(error: error).tap(&:fail)
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.11.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-03 00:00:00.000000000 Z
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.5.1
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