dot_options 0.1.1 → 0.1.2
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/README.md +6 -0
- data/lib/dot_options/version.rb +1 -1
- data/lib/dot_options.rb +9 -3
- 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: dcf63d2712a4a74313dbe914f5e52254243205f52c4715630a5dd84143dca366
|
4
|
+
data.tar.gz: 9be1281cc5d72168f23cb520d2d1e2a9a2c2a1427a3ff7298c48e8721de9a7a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fab0a8b1da7745406234335c7fe511df4f27e2149bfacc070fb72ed7116e3af794e1ab83659e5a7694a43c05599b0dde1f7fe4af038ff4b2d15d7052ce3f6d82
|
7
|
+
data.tar.gz: 17e1499a88d9a172fa07d265f765619840b22ff680bbfe0650777abfc3da049e9a0d1b767721fc18969d1b1ded40f7db949d418e175387173fa90fe450c6261f
|
data/README.md
CHANGED
@@ -45,6 +45,12 @@ puts options
|
|
45
45
|
# ... or a compact inspection string for any branch
|
46
46
|
p options.skin
|
47
47
|
#=> <background: <color: :black, texture: "Stripes">>
|
48
|
+
|
49
|
+
# Access is also possible using []
|
50
|
+
p options.skin[:background].color
|
51
|
+
p options.skin[:background][:color]
|
52
|
+
#=> :black
|
53
|
+
#=> :black
|
48
54
|
```
|
49
55
|
|
50
56
|
### Subclassing
|
data/lib/dot_options/version.rb
CHANGED
data/lib/dot_options.rb
CHANGED
@@ -2,15 +2,19 @@ class DotOptions
|
|
2
2
|
attr_reader :_options
|
3
3
|
attr_accessor :_key, :_parent, :_full_path
|
4
4
|
|
5
|
-
def initialize(base_options =
|
5
|
+
def initialize(base_options = nil, &block)
|
6
6
|
@_key = nil
|
7
7
|
@_parent = nil
|
8
8
|
@_options = []
|
9
9
|
@_full_path = []
|
10
|
-
_build_options
|
10
|
+
_build_options(base_options || {})
|
11
11
|
instance_eval(&block) if block
|
12
12
|
end
|
13
13
|
|
14
|
+
def [](key)
|
15
|
+
_options.include?(key.to_sym) ? send(key.to_sym) : nil
|
16
|
+
end
|
17
|
+
|
14
18
|
def inspect
|
15
19
|
"<#{_options.map { |key| "#{key}: #{send(key).inspect}" }.join(', ')}>"
|
16
20
|
end
|
@@ -57,7 +61,9 @@ private
|
|
57
61
|
end
|
58
62
|
|
59
63
|
def _define_accessor(key)
|
60
|
-
|
64
|
+
raise NameError, "invalid attribute name `#{key}'" unless key.respond_to?(:to_sym)
|
65
|
+
|
66
|
+
_options.push key.to_sym
|
61
67
|
singleton_class.class_eval do
|
62
68
|
attr_accessor key.to_sym
|
63
69
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dot_options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Convert any hash to a deep dot-notation object
|
14
14
|
email: db@dannyben.com
|