loadable_config 1.0.0 → 1.0.3

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: 2f9e359a1aa612416d1e8c84476e0f2e955208816710333d0d94e88dbcdd07a0
4
- data.tar.gz: 5cea5fb4d8af5246fd5b36906f4120ea9a1e128a58772fe856c2ddeb467fab44
3
+ metadata.gz: 33c373a5e0f4a214006136bab94ad6c340569d39243d42239aa6d585666b5504
4
+ data.tar.gz: 346a2170ef3e5c8c8c675ee63e725d775fe6b58918f37fb5cc90b720277cf7f9
5
5
  SHA512:
6
- metadata.gz: ebe69bc54c01a15a12e0611aabace5ed1ed5fd269b0ca2ae66b1bffd291128410f2d8efa634c6ddaa8241af4a16ed559d32a8b3bc4f36dd97fbf73f133294240
7
- data.tar.gz: cc068e42ecbf05a68307929ece847b5b3da1a8c525b1a8062df16a23c23f791f86cf833eed87741c10b4bd75fdc339a4ca4d3f8adf050e7b3ec08adc26cac735
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: circleci/ruby:<< parameters.ruby-version >>
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.5'
86
- ruby-version: "2.5"
85
+ name: 'ruby 2.7'
86
+ ruby-version: "2.7"
87
87
  - test:
88
- name: 'ruby 2.6'
89
- ruby-version: "2.6"
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.5'
93
- - 'ruby 2.6'
95
+ - 'ruby 2.7'
96
+ - 'ruby 3.0'
97
+ - 'ruby 3.1'
94
98
  filters:
95
99
  branches:
96
100
  only: master
@@ -1,3 +1,3 @@
1
1
  class LoadableConfig
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -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: {}, optional: false, serializer: nil)
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.kind_of?(Array)
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, [], [], true)
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
- value = config[attr.name]
115
- if attr.serializer
116
- value = attr.serializer.load(value)
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.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: 2019-04-08 00:00:00.000000000 Z
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.0.3
109
+ rubygems_version: 3.3.11
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: Simple declarative configuration files