verbalize 1.2.0 → 1.3.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: 1a62bdd3cdb29ee92c019943093d0808d2083531
4
- data.tar.gz: 236446bbba2989ca23cab20956aeddedefd3b22b
3
+ metadata.gz: 61174d8fa1734e70a63a74b34060d056515098ca
4
+ data.tar.gz: b3fc22d20687f9eba615606cdbc10865e56ea02f
5
5
  SHA512:
6
- metadata.gz: d508c37312260b5916ffc08eb3d84fa73a7df7afe5220c143673d44d9cb384893a70281931f5c22aab1bd895eb29ed253ecb799c4442d788cf58da6e3ba2c0ba
7
- data.tar.gz: 73e4886dd4c0f08ad21d7f7a134b8cb4949f34e4ef404f98a397ae5dbab338a62ff90613c0adb6772a7614ee9f3c6ba0834fde2638d6d99f470867b170f54480
6
+ metadata.gz: f3aeff77f6ce6012c78c597cfaadd60f19450e0cdfbd2c08e9f785b2a32b60d55685cc5571c97f0278a8c35795548811ade2e1dcc20209fe8bf7f9a600c5fbd5
7
+ data.tar.gz: f5c66899c7b5bcf67b088b92cbdeb1e81191d6479cea19204b9d8541cd144eec97a7f3b33e35a83ff67762429d703f05d896c8b3428e5ef679620de530eb69ab
data/.gitignore CHANGED
@@ -7,3 +7,6 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ # Ignore rubymine files
12
+ /.idea
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ AllCops:
2
2
  TargetRubyVersion: 2.1
3
3
 
4
4
  Metrics/LineLength:
5
- Max: 90
5
+ Max: 120
6
6
 
7
7
  Documentation:
8
8
  Enabled: false
@@ -9,13 +9,11 @@ module Verbalize
9
9
  end
10
10
 
11
11
  def body
12
- <<-BODY.chomp
13
- new(#{initialize_keywords_and_values}).send(:#{method_name})
14
- rescue UncaughtThrowError => uncaught_throw_error
15
- error = VerbalizeError.new("Unhandled fail! called with: \#{uncaught_throw_error.value.value.inspect}.")
16
- error.set_backtrace(uncaught_throw_error.backtrace[2..-1])
17
- raise error
18
- BODY
12
+ if all_keywords.empty?
13
+ " __verbalized_send!(:#{method_name})"
14
+ else
15
+ " __verbalized_send!(:#{method_name}, #{initialize_keywords_and_values})"
16
+ end
19
17
  end
20
18
  end
21
19
  end
@@ -9,15 +9,11 @@ module Verbalize
9
9
  end
10
10
 
11
11
  def body
12
- <<-BODY.chomp
13
- action = new(#{initialize_keywords_and_values})
14
- result = catch(:verbalize_error) { action.send(#{method_name.inspect}) }
15
- if result.is_a?(Result)
16
- result
17
- else
18
- Result.new(outcome: :ok, value: result)
19
- end
20
- BODY
12
+ if all_keywords.empty?
13
+ " __verbalized_send(:#{method_name})"
14
+ else
15
+ " __verbalized_send(:#{method_name}, #{initialize_keywords_and_values})"
16
+ end
21
17
  end
22
18
  end
23
19
  end
@@ -1,3 +1,3 @@
1
1
  module Verbalize
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
data/lib/verbalize.rb CHANGED
@@ -6,10 +6,11 @@ require 'verbalize/build_attribute_readers'
6
6
  require 'verbalize/result'
7
7
 
8
8
  module Verbalize
9
+ THROWN_SYMBOL = :verbalize_error
9
10
  VerbalizeError = Class.new(StandardError)
10
11
 
11
12
  def fail!(failure_value = nil)
12
- throw(:verbalize_error, Result.new(outcome: :error, value: failure_value))
13
+ throw(THROWN_SYMBOL, failure_value)
13
14
  end
14
15
 
15
16
  def self.included(target)
@@ -61,19 +62,30 @@ module Verbalize
61
62
  end
62
63
 
63
64
  def call
64
- action = new
65
- result = catch(:verbalize_error) { action.send(:call) }
66
- if result.is_a?(Result)
67
- result
68
- else
69
- Result.new(outcome: :ok, value: result)
70
- end
65
+ __verbalized_send(:call)
71
66
  end
72
67
 
73
68
  def call!
74
- new.send(:call)
69
+ __verbalized_send!(:call)
70
+ end
71
+
72
+ private
73
+
74
+ def __verbalized_send(method_name, *args)
75
+ outcome = :error
76
+ value = catch(:verbalize_error) do
77
+ value = new(*args).send(method_name)
78
+ # The outcome is :ok if the call didn't throw.
79
+ outcome = :ok
80
+ value
81
+ end
82
+ Result.new(outcome: outcome, value: value)
83
+ end
84
+
85
+ def __verbalized_send!(method_name, *args)
86
+ new(*args).send(method_name)
75
87
  rescue UncaughtThrowError => uncaught_throw_error
76
- fail_value = uncaught_throw_error.value.value
88
+ fail_value = uncaught_throw_error.value
77
89
  error = VerbalizeError.new("Unhandled fail! called with: #{fail_value.inspect}.")
78
90
  error.set_backtrace(uncaught_throw_error.backtrace[2..-1])
79
91
  raise error
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: verbalize
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-07 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler