tzispa_utils 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/tzispa/utils/duplicable.rb +18 -0
- data/lib/tzispa/utils/hash.rb +57 -0
- data/lib/tzispa/utils/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03d766019c0461759e3125672a0a7b29de48292e
|
4
|
+
data.tar.gz: 7e038be0727063d8744efa11654b7309ffa1dacf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3cb6386b173141f9d580a77af4f05f4ee9d6f3377d1529fecc3954d0bcfe449b82499bd58ca27568fd923f587d542640227278098bf2ceffa200d17c293c36d8
|
7
|
+
data.tar.gz: 119ca9321417f2378f4b5fcfa5b8c61267b0f1f7d50292cb68ee43edd512df462bb0d30f250a0fe75064d0fed27c3e808f62aa81889d0be9332ac6bbb4f51d73
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tzispa
|
2
|
+
module Utils
|
3
|
+
module Duplicable
|
4
|
+
|
5
|
+
def self.dup(value, &blk)
|
6
|
+
case value
|
7
|
+
when NilClass, FalseClass, TrueClass, Symbol, Numeric
|
8
|
+
value
|
9
|
+
when v = blk && blk.call(value)
|
10
|
+
v
|
11
|
+
else
|
12
|
+
value.dup
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'tzispa/utils/duplicable'
|
2
|
+
|
3
|
+
module Tzispa
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
DUPLICATE_LOGIC = proc do |value|
|
7
|
+
case value
|
8
|
+
when Hash
|
9
|
+
value.deep_dup
|
10
|
+
when ::Hash
|
11
|
+
Hash.new(value).deep_dup.to_h
|
12
|
+
end
|
13
|
+
end.freeze
|
14
|
+
|
15
|
+
refine Hash do
|
16
|
+
|
17
|
+
def symbolize!
|
18
|
+
keys.each do |k|
|
19
|
+
v = delete(k)
|
20
|
+
self[k.to_sym] = v
|
21
|
+
end
|
22
|
+
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def deep_symbolize!
|
27
|
+
keys.each do |k|
|
28
|
+
v = delete(k)
|
29
|
+
v = self.class.new(v).deep_symbolize! if v.respond_to?(:to_hash)
|
30
|
+
|
31
|
+
self[k.to_sym] = v
|
32
|
+
end
|
33
|
+
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def stringify!
|
38
|
+
keys.each do |k|
|
39
|
+
v = delete(k)
|
40
|
+
v = self.class.new(v).stringify! if v.respond_to?(:to_hash)
|
41
|
+
|
42
|
+
self[k.to_s] = v
|
43
|
+
end
|
44
|
+
|
45
|
+
self
|
46
|
+
end
|
47
|
+
|
48
|
+
def deep_dup
|
49
|
+
self.class.new.tap do |result|
|
50
|
+
@hash.each { |k, v| result[k] = Duplicable.dup(v, &DUPLICATE_LOGIC) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
data/lib/tzispa/utils/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tzispa_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Antonio Piñero
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
@@ -79,6 +79,8 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- lib/tzispa/utils.rb
|
81
81
|
- lib/tzispa/utils/decorator.rb
|
82
|
+
- lib/tzispa/utils/duplicable.rb
|
83
|
+
- lib/tzispa/utils/hash.rb
|
82
84
|
- lib/tzispa/utils/indenter.rb
|
83
85
|
- lib/tzispa/utils/integer.rb
|
84
86
|
- lib/tzispa/utils/string.rb
|