liquefied 0.5.0 → 0.6.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: 50c1f79371af354368d83154a1a86917333e3f98
4
- data.tar.gz: 037f2553339683c15825b4d00cae6cb7949ae5fc
3
+ metadata.gz: 07abe7eaa306cdf0434557af810894e649de256d
4
+ data.tar.gz: 1bd7c8ada8d13a1b72dcf5f4df92d2f3f8234c76
5
5
  SHA512:
6
- metadata.gz: ea47d5688cbf3d88ab3a019041a98f4fcd9c639e467dcbccc8af2fb62b8c70d413b0c4db3db8b21e17a183dc8011a0065a4027052668ca0f1e9590859b7c6b82
7
- data.tar.gz: 8f1eaa46ddb3a720e36fd662cc4d288c2a3f200816b9fb87851d415d21bf3ccc04da673b71a00d1d411558c285b036ff180b628aea15adbe7ee1d5aa065bea01
6
+ metadata.gz: ddb2355785e8d75631b3d773807894f2128503f5b3aabf17fa00b9e55c11486ca16b7c660ab48164bf297ca0d167b33a21399eccb8f655e4bb5e774841c80ef9
7
+ data.tar.gz: 163ce2931d86abf0888ea8b8d2860cf93ae75f3bca91ce882b7f737b92c88fcb26636b16668468dc56020d78a9ff4eb12a45d1c0644418ed68477126e87db984
@@ -1,3 +1,3 @@
1
1
  class Liquefied < BasicObject
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
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 _finalizer?(method)
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(@finalizer, *args, &block)
70
+ @original.public_send(method, *args, &block)
71
71
  end
72
72
  end
73
73
 
74
- def _finalizer?(method)
75
- return true if method == @finalizer
76
- both = [method, @finalizer]
77
- METHOD_ALIASES.any? { |m| (m & both).size == 2 }
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquefied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Vit