liquefied 0.4.1 → 0.5.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: 4664eed8676ebfe6494bab18d379088b49b2b0bd
4
- data.tar.gz: 2eb06dc76c152555ac10c94597cc94f31ab83255
3
+ metadata.gz: 50c1f79371af354368d83154a1a86917333e3f98
4
+ data.tar.gz: 037f2553339683c15825b4d00cae6cb7949ae5fc
5
5
  SHA512:
6
- metadata.gz: 682af052486e41fa76b5db04bed18f7be493cefc3f93297e06cf3b0040a2c4a75ba060c2d9150918dffa4213982690b1a32adea359e977fde37bf1771b72e706
7
- data.tar.gz: b3fe228f67153b2c4ed21dfbb7894204d058666792becf91f4c64c40c303e35b1ea4a7a27ae84af347d6da1b342dddf6c5e494878ec7ecdca3d5f90dd0194e23
6
+ metadata.gz: ea47d5688cbf3d88ab3a019041a98f4fcd9c639e467dcbccc8af2fb62b8c70d413b0c4db3db8b21e17a183dc8011a0065a4027052668ca0f1e9590859b7c6b82
7
+ data.tar.gz: 8f1eaa46ddb3a720e36fd662cc4d288c2a3f200816b9fb87851d415d21bf3ccc04da673b71a00d1d411558c285b036ff180b628aea15adbe7ee1d5aa065bea01
data/README.md CHANGED
@@ -21,7 +21,14 @@ value to its output format. The default finalizer is `to_s`, which makes this
21
21
  pattern helpful for implicit formatting in templates, so `<%= price %>`
22
22
  outputs the formatted value.
23
23
 
24
- The finalizer can be set to any other method you want.
24
+ The finalizer can be set to any other method you want.
25
+
26
+ Casting to the same type as the original will unwrap the original object:
27
+
28
+ ```
29
+ count = Liquefied.new(1234) { "1,234" }
30
+ count.to_i # 1234
31
+ ```
25
32
 
26
33
  ### Use with ActiveSupport Core Extensions
27
34
 
@@ -1,3 +1,3 @@
1
1
  class Liquefied < BasicObject
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/liquefied.rb CHANGED
@@ -6,6 +6,8 @@ class Liquefied < BasicObject
6
6
  [:to_s, :to_str]
7
7
  ]
8
8
 
9
+ CAST_PREFIX = "to_".freeze
10
+
9
11
  # Public: Wrap an object with a default finalizer method
10
12
  #
11
13
  # The object remains wrapped and responds to all its original methods
@@ -39,8 +41,8 @@ class Liquefied < BasicObject
39
41
  @original == other
40
42
  end
41
43
 
42
- def respond_to?(meth)
43
- @original.respond_to?(meth)
44
+ def respond_to?(meth, include_all=false)
45
+ @original.respond_to?(meth, include_all)
44
46
  end
45
47
 
46
48
  private
@@ -50,7 +52,7 @@ class Liquefied < BasicObject
50
52
  _finalize!(*args, &block)
51
53
  else
52
54
  result = @original.public_send(method, *args, &block)
53
- if result.class == @original.class
55
+ if result.class == @original.class && !method.to_s.start_with?(CAST_PREFIX)
54
56
  ::Liquefied.new(result, *@default_args, method: @finalizer, &@default_block)
55
57
  else
56
58
  result
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquefied
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Vit
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-18 00:00:00.000000000 Z
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler