clean-hash 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.version +1 -1
- data/lib/clean-hash.rb +1 -0
- data/lib/clean-hash/base.rb +1 -1
- data/lib/clean-hash/hash_pollute.rb +2 -2
- data/lib/clean-hash/opts_hash.rb +41 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8da8615041dbba1d87e61ea20b29829ec35a5c6143020b2da7195cd39807dc1
|
4
|
+
data.tar.gz: 03e0e0588325dca5eb1ad9c61fbace8efc0541f7c46a54c669a9aa2b798bd9ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16687111810848bf0fad3a7f00560621d96b0be2aadc6593536f1e11a9e787f25716a42ff1e92ac2efe41a6cb713d7ad3776dea72b897143a292717e21679a85
|
7
|
+
data.tar.gz: ebd5a5eafbf830059730a6b1e9c1a375f2a0e5cc194f6b4bee279b9d1bcaebe994d702d57226b48ce7b5f1e244f06343343c09115b28a7e774acf20e93a10194
|
data/.version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.1
|
data/lib/clean-hash.rb
CHANGED
data/lib/clean-hash/base.rb
CHANGED
@@ -22,7 +22,7 @@ class CleanHash
|
|
22
22
|
self[key] = nil unless key?(key)
|
23
23
|
end
|
24
24
|
|
25
|
-
::CleanHash.new self
|
25
|
+
::CleanHash::OptsHash.new self
|
26
26
|
else
|
27
27
|
supported = %i{safe mutex strict}
|
28
28
|
raise ArgumentError, 'Unsupported type "%s", supported: %s' % [mode, supported] if mode && !supported.include?(mode)
|
@@ -40,7 +40,7 @@ class CleanHash
|
|
40
40
|
# coverts keys to empty hash methods and returns read_only hash
|
41
41
|
def to_ch strict=false
|
42
42
|
hash = inject({}) { |h, key| h[key] = nil; h }
|
43
|
-
::CleanHash.new hash
|
43
|
+
::CleanHash::OptsHash.new hash
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# @ivars = [:foo, :bar].to_ch
|
2
|
+
# @ivars = {foo: nil, bar: 2}.to_ch [:foo, :bar, :baz]
|
3
|
+
|
4
|
+
class CleanHash
|
5
|
+
class OptsHash
|
6
|
+
def initialize *hash
|
7
|
+
if hash.first.class == Hash
|
8
|
+
@hash = hash.first
|
9
|
+
else
|
10
|
+
@hash = hash.inject({}) { |h, el| h[el.to_sym] = nil; h }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def [] key
|
15
|
+
method_missing key
|
16
|
+
end
|
17
|
+
|
18
|
+
def []= key, value
|
19
|
+
method_missing '%s=' % key, value
|
20
|
+
end
|
21
|
+
|
22
|
+
def method_missing name, value=nil
|
23
|
+
name = name.to_s
|
24
|
+
is_set = !!name.sub!('=', '')
|
25
|
+
name = name.to_sym
|
26
|
+
|
27
|
+
raise NoMethodError.new('Key %s not found' % name) unless @hash.has_key?(name)
|
28
|
+
|
29
|
+
if is_set
|
30
|
+
@hash[name] = value
|
31
|
+
else
|
32
|
+
@hash[name]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_h
|
37
|
+
@hash.dup
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clean-hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hashie
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- "./lib/clean-hash/deep_merge.rb"
|
37
37
|
- "./lib/clean-hash/hash_pollute.rb"
|
38
38
|
- "./lib/clean-hash/mutex_hash.rb"
|
39
|
+
- "./lib/clean-hash/opts_hash.rb"
|
39
40
|
- "./lib/clean-hash/pollute.rb"
|
40
41
|
homepage: https://github.com/dux/clean-hash
|
41
42
|
licenses:
|