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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b55ae95092dbd645f059f641d88e38d989d054e3
4
- data.tar.gz: 9616fc67b77bb2cd386f715d6b443c73422ac5ec
3
+ metadata.gz: 03d766019c0461759e3125672a0a7b29de48292e
4
+ data.tar.gz: 7e038be0727063d8744efa11654b7309ffa1dacf
5
5
  SHA512:
6
- metadata.gz: c3400b388e83f3996bc67e135ca1e80fa7c95a7962835a56c6cb1e1ac782433e6f2f5fb8ebdffcc864ac07ce342d6fd958024483eaef44cb9a3229197de5a614
7
- data.tar.gz: 7b56e7502e060edf19741caf5e54244475714845341c2c2b9dad2036e1c957f8560adc08b080e941c24352a42d91eef04110a191a4716fdcc9daf75a0f99999a
6
+ metadata.gz: 3cb6386b173141f9d580a77af4f05f4ee9d6f3377d1529fecc3954d0bcfe449b82499bd58ca27568fd923f587d542640227278098bf2ceffa200d17c293c36d8
7
+ data.tar.gz: 119ca9321417f2378f4b5fcfa5b8c61267b0f1f7d50292cb68ee43edd512df462bb0d30f250a0fe75064d0fed27c3e808f62aa81889d0be9332ac6bbb4f51d73
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  Tzispa Utils
2
2
 
3
+ ## v0.3.1
4
+ - added Hash refinement
5
+
3
6
  ## v0.3.0
4
7
  - remove String module keeping only String refinement
5
8
  - added integer refinement
@@ -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
@@ -3,7 +3,7 @@
3
3
  module Tzispa
4
4
  module Utils
5
5
 
6
- VERSION = '0.3.0'
6
+ VERSION = '0.3.1'
7
7
  NAME = 'Tzispa Utils'
8
8
  GEM_NAME = 'tzispa_utils'
9
9
 
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.0
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-10 00:00:00.000000000 Z
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