hash_wia 0.7.9 → 0.8.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/.version +1 -2
- data/lib/hash_wia/class.rb +30 -12
- data/lib/hash_wia/module.rb +2 -2
- data/lib/hash_wia/pollute.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47e5d1296ecbfb525c7f42577fc5b4206384c6a39a28d7ad85b277f208e6f779
|
4
|
+
data.tar.gz: 224acde315b8df0b2d04a606ee866261f5af52f066c74b39119ee2af8e901ea9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbafc17a9cfdcc4425388ee8c7cb8314c2e1fa1d379ab06a15b210e007dc8a8cb9185479a5bc9ddb3b158090e31d2eed3b1ccf7fed32fca14bf54be6f75ca2dc
|
7
|
+
data.tar.gz: 3ce638343e78ea595620113d1c632cfaf5b6bcb962a9c95d4c42a3728c10457a286d04243be5aca208356a8bc1fc964ca2528ef78964624511d75fc978d850eb
|
data/.version
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
0.
|
2
|
-
|
1
|
+
0.8.0
|
data/lib/hash_wia/class.rb
CHANGED
@@ -4,13 +4,15 @@ end
|
|
4
4
|
|
5
5
|
class HashWia
|
6
6
|
class NamedOptions
|
7
|
-
def initialize hash
|
8
|
-
@hash
|
7
|
+
def initialize hash, &block
|
8
|
+
@hash = hash
|
9
|
+
@block = block
|
9
10
|
end
|
10
11
|
|
11
|
-
def set constant, code,
|
12
|
+
def set constant, code, value
|
13
|
+
@block.call constant.to_s, code, value
|
12
14
|
@hash[constant.to_s] = code
|
13
|
-
@hash[code] =
|
15
|
+
@hash[code] = value
|
14
16
|
end
|
15
17
|
|
16
18
|
def method_missing code, key_val
|
@@ -28,21 +30,37 @@ end
|
|
28
30
|
# # or
|
29
31
|
# opt.set 'DONE', :d, 'Done'
|
30
32
|
# end
|
31
|
-
def HashWia klass = nil,
|
33
|
+
def HashWia klass = nil, opts = nil
|
32
34
|
if block_given?
|
33
35
|
hash = HashWia.new
|
34
36
|
|
35
|
-
if
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
if klass.class == Hash
|
38
|
+
opts = klass
|
39
|
+
klass = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
opts ||= {}
|
40
43
|
|
41
|
-
|
44
|
+
named_opts = HashWia::NamedOptions.new hash do |constant, code, value|
|
45
|
+
if opts[:constants]
|
46
|
+
if klass
|
47
|
+
klass.const_set "#{opts[:constants]}_#{constant}".upcase, code
|
48
|
+
else
|
49
|
+
raise "Host class not given (call as HashWia self, constants: ...)"
|
50
|
+
end
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
44
|
-
named_opts = HashWia::NamedOptions.new hash
|
45
54
|
yield named_opts
|
55
|
+
|
56
|
+
if opts[:method]
|
57
|
+
klass.define_singleton_method(opts[:method]) { hash }
|
58
|
+
end
|
59
|
+
|
60
|
+
unless opts[:freeze] == false
|
61
|
+
hash.freeze
|
62
|
+
end
|
63
|
+
|
46
64
|
hash
|
47
65
|
else
|
48
66
|
raise ArgumentError, 'Block not provided'
|
data/lib/hash_wia/module.rb
CHANGED
@@ -26,8 +26,8 @@ module HashWiaModule
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def []= key, value
|
29
|
-
if @frozen_keys
|
30
|
-
raise
|
29
|
+
if @frozen_keys && !keys.include?(key)
|
30
|
+
raise FrozenError, "HashWia keys are frozen and can't be modified (key: #{key})"
|
31
31
|
end
|
32
32
|
|
33
33
|
delete key
|
data/lib/hash_wia/pollute.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_wia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dino Reic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Gem provides simple access to common Ruby hash types bundled in one simple
|
14
14
|
class
|