liquefied 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/liquefied/version.rb +1 -1
- data/lib/liquefied.rb +11 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07abe7eaa306cdf0434557af810894e649de256d
|
4
|
+
data.tar.gz: 1bd7c8ada8d13a1b72dcf5f4df92d2f3f8234c76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddb2355785e8d75631b3d773807894f2128503f5b3aabf17fa00b9e55c11486ca16b7c660ab48164bf297ca0d167b33a21399eccb8f655e4bb5e774841c80ef9
|
7
|
+
data.tar.gz: 163ce2931d86abf0888ea8b8d2860cf93ae75f3bca91ce882b7f737b92c88fcb26636b16668468dc56020d78a9ff4eb12a45d1c0644418ed68477126e87db984
|
data/lib/liquefied/version.rb
CHANGED
data/lib/liquefied.rb
CHANGED
@@ -18,13 +18,13 @@ class Liquefied < BasicObject
|
|
18
18
|
# object - The original value to wrap
|
19
19
|
#
|
20
20
|
# @example
|
21
|
-
# Liquefied.new(12.333, :to_s) { |val| "%.2f" % val }
|
21
|
+
# Liquefied.new(12.333, method: [:to_s]) { |val| "%.2f" % val }
|
22
22
|
# Liquefied.new(Date.new(2016,1,1), :to_s, :long)
|
23
23
|
# #=> "January 1, 2016"
|
24
24
|
#
|
25
25
|
def initialize(original, *default_args, method: :to_s, &default_block)
|
26
26
|
@original = original
|
27
|
-
@finalizer = method
|
27
|
+
@finalizer = ::Kernel::Array(method)
|
28
28
|
@default_args = default_args
|
29
29
|
@default_block = default_block
|
30
30
|
end
|
@@ -48,8 +48,8 @@ class Liquefied < BasicObject
|
|
48
48
|
private
|
49
49
|
|
50
50
|
def method_missing(method, *args, &block)
|
51
|
-
if
|
52
|
-
_finalize!(*args, &block)
|
51
|
+
if (final_method = _get_finalizer(method))
|
52
|
+
_finalize!(final_method, *args, &block)
|
53
53
|
else
|
54
54
|
result = @original.public_send(method, *args, &block)
|
55
55
|
if result.class == @original.class && !method.to_s.start_with?(CAST_PREFIX)
|
@@ -60,21 +60,22 @@ class Liquefied < BasicObject
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
def _finalize!(*args, &block)
|
63
|
+
def _finalize!(method, *args, &block)
|
64
64
|
if block
|
65
65
|
block.call(@original)
|
66
66
|
elsif @default_block
|
67
67
|
@default_block.call([@original, *args])
|
68
68
|
else
|
69
69
|
args = @default_args if args.empty?
|
70
|
-
@original.public_send(
|
70
|
+
@original.public_send(method, *args, &block)
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
def
|
75
|
-
return
|
76
|
-
both = [method,
|
77
|
-
METHOD_ALIASES.
|
74
|
+
def _get_finalizer(method)
|
75
|
+
return method if @finalizer.include?(method)
|
76
|
+
both = [method, *@finalizer]
|
77
|
+
aliases = METHOD_ALIASES.find { |m| (m & both).size >= 2 }
|
78
|
+
aliases.find { |m| @original.respond_to?(m, true) } if aliases
|
78
79
|
end
|
79
80
|
|
80
81
|
end
|