config_default 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 +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/lib/config_default/struct.rb +7 -1
- data/lib/config_default/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7e18b5eb5ba11e06e39b8ecc08aa74d98a32dc0bfe36caa787978224f1aca90
|
4
|
+
data.tar.gz: fee80751ea9a44bda3acbbb29d9714f287c6055f6c52c241251d7d8b42440df0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6da506d9904ebaf20ffd47fb3d9e0aeef689fa3bb0e39950670f7ecc2fc24f22baf064ab38b23ab7f1ed5a88a6286a6d2aba0abd22291e84229a2f905d92f28
|
7
|
+
data.tar.gz: 444e8ddfdcee3d3ba48bbe8e3b19b83fde496cc9429b68d8df973de971f6994106d6b2dde311f795f02da2a8d0ef7a743a0ae07ccc25e651ccdf1cf5b4334df8
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class ConfigDefault::Struct
|
4
|
+
RESERVED_METHODS = %i[method_missing respond_to_missing? to_hash].freeze
|
5
|
+
|
4
6
|
def initialize(attributes = {}, recursive: false, allow_nil: false)
|
5
7
|
@attributes = ActiveSupport::HashWithIndifferentAccess.new(attributes)
|
6
8
|
@allow_nil = allow_nil
|
@@ -13,6 +15,11 @@ class ConfigDefault::Struct
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
@attributes.each do |key, value|
|
19
|
+
next if RESERVED_METHODS.include?(key.to_sym)
|
20
|
+
define_singleton_method(key) { value }
|
21
|
+
end
|
22
|
+
|
16
23
|
@attributes.freeze
|
17
24
|
end
|
18
25
|
|
@@ -21,7 +28,6 @@ class ConfigDefault::Struct
|
|
21
28
|
end
|
22
29
|
|
23
30
|
def method_missing(method, *_args)
|
24
|
-
return @attributes[method] if @attributes.key?(method)
|
25
31
|
raise StandardError.new("There is no option :#{method} in configuration.") unless @allow_nil
|
26
32
|
end
|
27
33
|
|