nested_hash_builder 0.1.0 → 0.1.1
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/.ruby-version +1 -0
- data/lib/nested_hash_builder/version.rb +1 -1
- data/lib/nested_hash_builder.rb +16 -4
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27e48078e46d2370f254af47a5af0b815c761e2bd24179d6cd45f84f707241b7
|
4
|
+
data.tar.gz: 7ee2bce52dd09cc3ce9ffa1e7511cbfc33c081ede01a58a857176f0eb9f854e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4137fe58376f5edec945a7fc216eb14a5b6081bae71334107ebb56c25963ce185c7f9bbe39c9dc4b4488a665c5a98f52544440ad6e4484303b513ba2d173f3c3
|
7
|
+
data.tar.gz: 60c2ce72259961abe8d7d7b995616f25cef72cf1357ddb3ed7c4f8cfddbe7279ec8f6ba2c72d463405f6fd116650e6b2d89f8264088261a731deaa174920134c
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.4.5
|
data/lib/nested_hash_builder.rb
CHANGED
@@ -31,9 +31,15 @@ module NestedHashBuilder
|
|
31
31
|
alias build call
|
32
32
|
end
|
33
33
|
|
34
|
+
module ProxyConstants
|
35
|
+
T = ::T
|
36
|
+
end
|
37
|
+
|
34
38
|
# Object that is the receiver of all
|
35
39
|
# the building methods.
|
36
40
|
class Proxy < ::BasicObject
|
41
|
+
include ProxyConstants
|
42
|
+
|
37
43
|
#: (?base: Hash[untyped, untyped], ?symbolize: bool) -> void
|
38
44
|
def initialize(base: {}, symbolize: true)
|
39
45
|
@hash = base.dup
|
@@ -123,7 +129,7 @@ module NestedHashBuilder
|
|
123
129
|
# @param names [Array<Symbol>]
|
124
130
|
#: (*Symbol | String) -> bool
|
125
131
|
def key?(*names)
|
126
|
-
|
132
|
+
!T.unsafe(self).dig!(*names).nil?
|
127
133
|
end
|
128
134
|
|
129
135
|
# Gets a value of a particular key in the current context.
|
@@ -154,7 +160,7 @@ module NestedHashBuilder
|
|
154
160
|
#
|
155
161
|
#: (*Symbol | String) -> bool
|
156
162
|
def local_key?(*names)
|
157
|
-
|
163
|
+
!T.unsafe(self).local_dig!(*names).nil?
|
158
164
|
end
|
159
165
|
|
160
166
|
#: -> Hash[Symbol | String, untyped]
|
@@ -162,14 +168,20 @@ module NestedHashBuilder
|
|
162
168
|
@hash
|
163
169
|
end
|
164
170
|
|
171
|
+
private
|
172
|
+
|
173
|
+
def builder_method?(name)
|
174
|
+
!name.end_with?('?') && !name.end_with?('!')
|
175
|
+
end
|
176
|
+
|
165
177
|
def method_missing(method_name, *args, &block)
|
166
|
-
super
|
178
|
+
super unless builder_method?(method_name)
|
167
179
|
|
168
180
|
key!(method_name, args.first, &block)
|
169
181
|
end
|
170
182
|
|
171
183
|
def respond_to_missing?(method_name, *_args)
|
172
|
-
return false if
|
184
|
+
return false if builder_method?(method_name)
|
173
185
|
|
174
186
|
true
|
175
187
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested_hash_builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Drewniak
|
@@ -31,6 +31,7 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
33
|
- ".github/workflows/ci.yml"
|
34
|
+
- ".ruby-version"
|
34
35
|
- CHANGELOG.md
|
35
36
|
- README.md
|
36
37
|
- Rakefile
|