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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/hash_wia/class.rb +21 -13
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 21df027abd49f7b71a57b22e4b33eae7a9446132b7afb300368de7d0d4b7f365
4
- data.tar.gz: 529fe29a3eec11e03a54e99770ea8706bae0a9c24e6797e9cca2ad1e47223668
3
+ metadata.gz: 47e5d1296ecbfb525c7f42577fc5b4206384c6a39a28d7ad85b277f208e6f779
4
+ data.tar.gz: 224acde315b8df0b2d04a606ee866261f5af52f066c74b39119ee2af8e901ea9
5
5
  SHA512:
6
- metadata.gz: 853abb6448ccc27730dba7880edd91f70e54d1a865537397ede4706c1b10fbfa207236090353da19ef7bfadb3fb20673b4c198e56746cd40201ba77056cbb163
7
- data.tar.gz: fa564c45e2b991fce99ef8c6f0dbdc786c92a2d1de55533b9bd4d0e9da2448eb12a3b8aa9ae3c28441a423da084a108bf6f1e7e584354b070e5ee368644e0d10
6
+ metadata.gz: cbafc17a9cfdcc4425388ee8c7cb8314c2e1fa1d379ab06a15b210e007dc8a8cb9185479a5bc9ddb3b158090e31d2eed3b1ccf7fed32fca14bf54be6f75ca2dc
7
+ data.tar.gz: 3ce638343e78ea595620113d1c632cfaf5b6bcb962a9c95d4c42a3728c10457a286d04243be5aca208356a8bc1fc964ca2528ef78964624511d75fc978d850eb
data/.version CHANGED
@@ -1 +1 @@
1
- 0.7.12
1
+ 0.8.0
@@ -4,13 +4,15 @@ end
4
4
 
5
5
  class HashWia
6
6
  class NamedOptions
7
- def initialize hash
8
- @hash = hash
7
+ def initialize hash, &block
8
+ @hash = hash
9
+ @block = block
9
10
  end
10
11
 
11
- def set constant, code, name
12
+ def set constant, code, value
13
+ @block.call constant.to_s, code, value
12
14
  @hash[constant.to_s] = code
13
- @hash[code] = name.to_s
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, name = nil, opts = 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
- if name
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
- klass.define_singleton_method(name) { klass.const_get(constant) }
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 !opts || opts[:freeze] != false
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.7.12
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-06 00:00:00.000000000 Z
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