loadable_config 1.0.0 → 1.0.3
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/.circleci/config.yml +11 -7
- data/lib/loadable_config/version.rb +1 -1
- data/lib/loadable_config.rb +16 -8
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c373a5e0f4a214006136bab94ad6c340569d39243d42239aa6d585666b5504
|
4
|
+
data.tar.gz: 346a2170ef3e5c8c8c675ee63e725d775fe6b58918f37fb5cc90b720277cf7f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a7a4699f631c1929510007fb0bb2f57aedbe8b9dd948f2646fada1e5e1ab9ccad49fe33b5b801450658e667acf308c481e5222cb3c80ab7396c4f99ec4ad972
|
7
|
+
data.tar.gz: 444ed617779485ad69f4667c4be6d6781e57b304d1e7d24b9860c3f324d3f8fbc40f46f265d428bf131689228d1a8ea9c6d95240a5c9a26b648a93bad394af5a
|
data/.circleci/config.yml
CHANGED
@@ -10,7 +10,7 @@ executors:
|
|
10
10
|
type: string
|
11
11
|
default: "Gemfile"
|
12
12
|
docker:
|
13
|
-
- image:
|
13
|
+
- image: cimg/ruby:<< parameters.ruby-version >>
|
14
14
|
environment:
|
15
15
|
BUNDLE_JOBS: 3
|
16
16
|
BUNDLE_RETRY: 3
|
@@ -82,15 +82,19 @@ workflows:
|
|
82
82
|
build:
|
83
83
|
jobs:
|
84
84
|
- test:
|
85
|
-
name: 'ruby 2.
|
86
|
-
ruby-version: "2.
|
85
|
+
name: 'ruby 2.7'
|
86
|
+
ruby-version: "2.7"
|
87
87
|
- test:
|
88
|
-
name: 'ruby
|
89
|
-
ruby-version: "
|
88
|
+
name: 'ruby 3.0'
|
89
|
+
ruby-version: "3.0"
|
90
|
+
- test:
|
91
|
+
name: 'ruby 3.1'
|
92
|
+
ruby-version: "3.1"
|
90
93
|
- publish:
|
91
94
|
requires:
|
92
|
-
- 'ruby 2.
|
93
|
-
- 'ruby
|
95
|
+
- 'ruby 2.7'
|
96
|
+
- 'ruby 3.0'
|
97
|
+
- 'ruby 3.1'
|
94
98
|
filters:
|
95
99
|
branches:
|
96
100
|
only: master
|
data/lib/loadable_config.rb
CHANGED
@@ -7,12 +7,13 @@ require 'yaml'
|
|
7
7
|
require 'singleton'
|
8
8
|
|
9
9
|
class LoadableConfig
|
10
|
-
Attribute = Struct.new(:name, :type, :schema, :optional, :serializer)
|
10
|
+
Attribute = Struct.new(:name, :type, :schema, :optional, :serializer, :default)
|
11
11
|
|
12
12
|
class << self
|
13
13
|
attr_reader :_attributes, :_config_file
|
14
14
|
|
15
15
|
def inherited(subclass)
|
16
|
+
super
|
16
17
|
subclass.send(:include, Singleton)
|
17
18
|
end
|
18
19
|
|
@@ -20,7 +21,7 @@ class LoadableConfig
|
|
20
21
|
@_config_file = path
|
21
22
|
end
|
22
23
|
|
23
|
-
def attribute(attr, type: :string, schema: {},
|
24
|
+
def attribute(attr, type: :string, schema: {}, serializer: nil, default: nil, optional: !default.nil?)
|
24
25
|
@_attributes ||= []
|
25
26
|
attr = attr.to_sym
|
26
27
|
if ATTRIBUTE_BLACKLIST.include?(attr)
|
@@ -28,11 +29,12 @@ class LoadableConfig
|
|
28
29
|
'attributes must not collide with class methods of LoadableConfig')
|
29
30
|
end
|
30
31
|
|
31
|
-
type = [type] unless type.
|
32
|
+
type = [type] unless type.is_a?(Array)
|
32
33
|
type.map! { |t| t.to_s }
|
33
34
|
|
34
|
-
_attributes << Attribute.new(attr.to_s, type, schema, optional, serializer)
|
35
|
+
_attributes << Attribute.new(attr.to_s, type, schema, optional, serializer, default)
|
35
36
|
attr_accessor attr
|
37
|
+
|
36
38
|
define_singleton_method(attr) { instance.send(attr) }
|
37
39
|
end
|
38
40
|
|
@@ -50,6 +52,7 @@ class LoadableConfig
|
|
50
52
|
if @@_configuration.frozen?
|
51
53
|
raise ArgumentError.new('Cannot configure LoadableConfig: already configured')
|
52
54
|
end
|
55
|
+
|
53
56
|
yield(@@_configuration)
|
54
57
|
@@_configuration.freeze
|
55
58
|
end
|
@@ -87,7 +90,7 @@ class LoadableConfig
|
|
87
90
|
config_data = preprocessor.call(config_data)
|
88
91
|
end
|
89
92
|
|
90
|
-
config = YAML.safe_load(config_data,
|
93
|
+
config = YAML.safe_load(config_data, aliases: true)
|
91
94
|
unless config
|
92
95
|
raise RuntimeError.new("Cannot configure #{self.class.name}: "\
|
93
96
|
"Configuration file empty for #{self.class.name}.")
|
@@ -111,10 +114,15 @@ class LoadableConfig
|
|
111
114
|
end
|
112
115
|
|
113
116
|
self.class._attributes.each do |attr|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
+
if config.has_key?(attr.name)
|
118
|
+
value = config[attr.name]
|
119
|
+
if attr.serializer
|
120
|
+
value = attr.serializer.load(value)
|
121
|
+
end
|
122
|
+
else
|
123
|
+
value = attr.default
|
117
124
|
end
|
125
|
+
|
118
126
|
self.public_send(:"#{attr.name}=", value)
|
119
127
|
end
|
120
128
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loadable_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- iKnow Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_schema
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
- !ruby/object:Gem::Version
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
|
-
rubygems_version: 3.
|
109
|
+
rubygems_version: 3.3.11
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Simple declarative configuration files
|