power_converter 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/power_converter.rb +5 -2
- data/lib/power_converter/version.rb +1 -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: ee2c06493a4caf6e24704ac9d324b6ea576d2e7e
|
4
|
+
data.tar.gz: 5f4debece4a5af37189f0598b7e6d5b3d49220ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a2e255d8965a7a424d6b10d2f3c6e2a26347560fab683c5e07deda51e51fb47ab9eccc4e44bb5f11181d07474cd499bd68f9a30335ad7d5e43c0c0e42fd5bfa
|
7
|
+
data.tar.gz: e75fc34a55012c36cf7d1d8972aaedd5491c44541057a7fcc7baeb700ec979156868033723e198efd31eeb609d02a39d02992539711ca92f1ae011c554af9955
|
data/lib/power_converter.rb
CHANGED
@@ -130,6 +130,8 @@ module PowerConverter
|
|
130
130
|
# @option options [Symbol] :to the named_conversion that has been registered
|
131
131
|
#
|
132
132
|
# @return [Object] the resulting converted object
|
133
|
+
# @yield Yield control to caller if the value could not be converted; This is a good fallback mechanism.
|
134
|
+
#
|
133
135
|
#
|
134
136
|
# @raise [ConverterNotFoundError] if the named converter is not found
|
135
137
|
# @raise [ConversionError] if the named converter returned a nil value
|
@@ -155,6 +157,7 @@ module PowerConverter
|
|
155
157
|
return value.public_send("to_#{named_converter}") if value.respond_to?("to_#{named_converter}", false)
|
156
158
|
returning_value = converter_for(named_converter).call(value, *scope)
|
157
159
|
return returning_value unless returning_value.nil?
|
160
|
+
return yield if block_given?
|
158
161
|
fail ConversionError.new(value, options)
|
159
162
|
end
|
160
163
|
|
@@ -234,7 +237,7 @@ module PowerConverter
|
|
234
237
|
|
235
238
|
# Useful for when you want to know if a method name is a valid conversion
|
236
239
|
# method name.
|
237
|
-
CONVERSION_METHOD_REGEXP = /\A#{CONVERSION_METHOD_PREFIX}(.+)\Z
|
240
|
+
CONVERSION_METHOD_REGEXP = /\A#{CONVERSION_METHOD_PREFIX}(.+)\Z/
|
238
241
|
|
239
242
|
# @api private
|
240
243
|
# @since 0.0.2
|
@@ -254,7 +257,7 @@ module PowerConverter
|
|
254
257
|
def method_missing(method_name, *args, &block)
|
255
258
|
named_converter = extract_named_converter_from(method_name)
|
256
259
|
if named_converter
|
257
|
-
convert(*args, to: named_converter)
|
260
|
+
convert(*args, to: named_converter, &block)
|
258
261
|
else
|
259
262
|
super
|
260
263
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: power_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Friesen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|