liquefied 0.4.1 → 0.5.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/README.md +8 -1
- data/lib/liquefied/version.rb +1 -1
- data/lib/liquefied.rb +5 -3
- 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: 50c1f79371af354368d83154a1a86917333e3f98
|
4
|
+
data.tar.gz: 037f2553339683c15825b4d00cae6cb7949ae5fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/liquefied/version.rb
CHANGED
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
|
+
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-
|
11
|
+
date: 2016-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|