hash_wia 0.7.12 → 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 -1
- data/lib/hash_wia/class.rb +21 -13
- 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 +1 @@
|
|
1
|
-
0.
|
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,7 +30,7 @@ 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
|
|
@@ -37,19 +39,25 @@ def HashWia klass = nil, name = nil, opts = nil
|
|
37
39
|
klass = nil
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
|
-
if !opts || opts[:constant] != false
|
42
|
-
constant = name.to_s.upcase
|
43
|
-
klass.const_set constant, hash
|
44
|
-
end
|
42
|
+
opts ||= {}
|
45
43
|
|
46
|
-
|
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
|
47
52
|
end
|
48
53
|
|
49
|
-
named_opts = HashWia::NamedOptions.new hash
|
50
54
|
yield named_opts
|
51
55
|
|
52
|
-
if
|
56
|
+
if opts[:method]
|
57
|
+
klass.define_singleton_method(opts[:method]) { hash }
|
58
|
+
end
|
59
|
+
|
60
|
+
unless opts[:freeze] == false
|
53
61
|
hash.freeze
|
54
62
|
end
|
55
63
|
|
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
|