dot_options 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2209fc78fa0d901b7662d743865fdaae4253e11542e940f42e3752f3ade4a31
4
- data.tar.gz: cfddbb2c664850d59d272de160b341f9f2e840c03280d05e1ee290ed7109b079
3
+ metadata.gz: dcf63d2712a4a74313dbe914f5e52254243205f52c4715630a5dd84143dca366
4
+ data.tar.gz: 9be1281cc5d72168f23cb520d2d1e2a9a2c2a1427a3ff7298c48e8721de9a7a6
5
5
  SHA512:
6
- metadata.gz: 0243d039b3d76e327abc4360df4e551ed14f09439bba4d2e4ad7134762bc8f504bc5e317953a3e9379d79a3e15d4bb713e16f1dd3708d816d888ef792b9628d5
7
- data.tar.gz: 4dc4ac826ae86597529fb577650a03bb5c55ef099a4c925f39f767ca2dfaf8c7e559efc36dbc54b66705299b7a11b034c497f3f9185aa7ce5f1b2f99b3e057be
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
@@ -1,3 +1,3 @@
1
1
  class DotOptions
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
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 = {}, &block)
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 base_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
- _options.push key
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.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-02 00:00:00.000000000 Z
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