configature 0.3.4 → 0.3.7

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: a224ef00f9af60ae0ba0763ccd95aa3fa1f96a0a2d1bc9065fd9901c9654334e
4
- data.tar.gz: fe233997b912aa51af9345f21aecb7401e957d8f3a9e3a1791ed143c7c8ca6f7
3
+ metadata.gz: '080afc9a5e1852192d430bb691b87260cbd9dbb5dedc5cd6803d4fb78aa2cb7e'
4
+ data.tar.gz: 294737d6d91bd078c95c7e7a908f088081a2c4143f5f4cba682034e09a915098
5
5
  SHA512:
6
- metadata.gz: 9ea6242794f99d7cafe567d80a1ed8b1baa5ec25329e7bdacd9e246f7e0775d8347acaad5d570e904a6707fef9ffef2d593468c1e4c9ffc3c69cb1c452211bd6
7
- data.tar.gz: 5b0af76af2347583a90091cc0717d2ecfe40a8c581032f438c7729a2ddbedadc0da867d5b3c87217df8b1185d4b82e717ae095c495b2cc5f56ea2f5c501787b7
6
+ metadata.gz: 602be0de3c36b974b2ce6af817c6e352fbdee38010fe1006b7a21dc5842af615f49adfd3f3503ad8f6d787f14e47feefae00cf4a0541cb00254d5299cd1c3dbc
7
+ data.tar.gz: 1e6d62685d3beab2bdf9ccdcca98943ce3a766cff07d2f2cf8dcb8d569cc9b5fb4326ebebd4392c5f5293c85d2b508429ab6f56a7fcf2057a2b6f3f203e49557
data/.travis.yml CHANGED
@@ -3,10 +3,8 @@ sudo: false
3
3
  language: ruby
4
4
  cache: bundler
5
5
  rvm:
6
- - 2.3.8
7
- - 2.4.9
8
- - 2.5.7
9
- - 2.6.5
10
- - 2.7.0
11
- - jruby-9.2.9.0
12
- before_install: gem install bundler -v 2.1.4
6
+ - 2.6.7
7
+ - 2.7.3
8
+ - 3.0.1
9
+ before_install:
10
+ - gem install bundler
data/Gemfile CHANGED
@@ -3,8 +3,11 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in configature.gemspec
4
4
  gemspec
5
5
 
6
+ ruby '>= 2.6.0'
7
+
6
8
  group :development do
7
9
  gem 'rake'
8
10
  gem 'bundler'
9
11
  gem 'rspec'
12
+ gem 'rspec-core'
10
13
  end
data/Gemfile.lock CHANGED
@@ -1,26 +1,26 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- configature (0.3.3)
4
+ configature (0.3.7)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  diff-lcs (1.4.4)
10
- rake (13.0.1)
11
- rspec (3.9.0)
12
- rspec-core (~> 3.9.0)
13
- rspec-expectations (~> 3.9.0)
14
- rspec-mocks (~> 3.9.0)
15
- rspec-core (3.9.2)
16
- rspec-support (~> 3.9.3)
17
- rspec-expectations (3.9.2)
10
+ rake (13.0.3)
11
+ rspec (3.10.0)
12
+ rspec-core (~> 3.10.0)
13
+ rspec-expectations (~> 3.10.0)
14
+ rspec-mocks (~> 3.10.0)
15
+ rspec-core (3.10.1)
16
+ rspec-support (~> 3.10.0)
17
+ rspec-expectations (3.10.1)
18
18
  diff-lcs (>= 1.2.0, < 2.0)
19
- rspec-support (~> 3.9.0)
20
- rspec-mocks (3.9.1)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-mocks (3.10.2)
21
21
  diff-lcs (>= 1.2.0, < 2.0)
22
- rspec-support (~> 3.9.0)
23
- rspec-support (3.9.3)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-support (3.10.2)
24
24
 
25
25
  PLATFORMS
26
26
  ruby
@@ -30,6 +30,10 @@ DEPENDENCIES
30
30
  configature!
31
31
  rake
32
32
  rspec
33
+ rspec-core
34
+
35
+ RUBY VERSION
36
+ ruby 3.0.1p64
33
37
 
34
38
  BUNDLED WITH
35
- 2.1.4
39
+ 2.2.16
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.4
1
+ 0.3.7
@@ -7,9 +7,9 @@ require_relative './namespace'
7
7
 
8
8
  class Configature::Config < Configature::Data
9
9
  # == Constants ============================================================
10
-
10
+
11
11
  # == Properties ===========================================================
12
-
12
+
13
13
  # == Class Methods ========================================================
14
14
 
15
15
  def self.config_dir
@@ -21,7 +21,9 @@ class Configature::Config < Configature::Data
21
21
  end
22
22
 
23
23
  def self.namespace(name, file: nil, env_suffix: '', extends: nil, &block)
24
- namespace = self.namespaces[name] = Configature::Namespace.new(name, env_suffix: env_suffix, extends: extends && self.namespaces[extends]).tap do |n|
24
+ extends &&= self.namespaces[extends]
25
+
26
+ namespace = self.namespaces[name] = Configature::Namespace.new(name, env_suffix: env_suffix, extends: extends).tap do |n|
25
27
  case (block&.arity)
26
28
  when nil
27
29
  nil
@@ -32,7 +34,7 @@ class Configature::Config < Configature::Data
32
34
  end
33
35
  end
34
36
 
35
- file = file&.to_s || name.to_s
37
+ file = (file || extends&.config_name || name).to_s
36
38
 
37
39
  if (file and !file.include?('.'))
38
40
  file += '.yml'
@@ -42,11 +44,9 @@ class Configature::Config < Configature::Data
42
44
  iv = :"@#{name}"
43
45
 
44
46
  singleton_class.send(:define_method, name) do
45
- config_path = File.expand_path(file, self.config_dir)
46
-
47
- config = Configature::Support.yaml_if_exist(config_path)
48
-
49
- instance_variable_get(iv) or instance_variable_set(iv, namespace.__instantiate(source: config))
47
+ instance_variable_get(iv) or instance_variable_set(iv, namespace.__instantiate(
48
+ source: Configature::Support.yaml_if_exist(File.expand_path(file, self.config_dir))
49
+ ))
50
50
  end
51
51
  end
52
52
  end
@@ -54,15 +54,17 @@ class Configature::Config < Configature::Data
54
54
  def self.namespaces
55
55
  @namespaces ||= { }
56
56
  end
57
-
57
+
58
58
  # == Instance Methods =====================================================
59
59
 
60
- def initialize(config_dir: nil, env: ENV)
60
+ def initialize(config_dir: nil, path: nil, env: ENV, data: nil)
61
61
  super(
62
62
  self.class.namespaces.map do |name, namespace|
63
- config_path = File.expand_path('%s.yml' % name, config_dir || self.class.config_dir)
63
+ config = data || begin
64
+ path ||= File.expand_path('%s.yml' % namespace.config_name, config_dir || self.class.config_dir)
64
65
 
65
- config = Configature::Support.yaml_if_exist(config_path)
66
+ Configature::Support.yaml_if_exist(path)
67
+ end
66
68
 
67
69
  [
68
70
  name,
@@ -19,8 +19,8 @@ class Configature::Data < OpenStruct
19
19
  # == Instance Methods =====================================================
20
20
 
21
21
  def to_h
22
- super.transform_values do |v|
23
- self.class.hashify(v)
24
- end
22
+ super.map do |k, v|
23
+ [ k, self.class.hashify(v) ]
24
+ end.to_h
25
25
  end
26
26
  end
@@ -40,6 +40,7 @@ class Configature::Namespace
40
40
  # == Properties ===========================================================
41
41
 
42
42
  attr_reader :name
43
+ attr_reader :config_name
43
44
  attr_reader :env_name_prefix
44
45
  attr_reader :namespaces
45
46
  attr_reader :parameters
@@ -53,18 +54,25 @@ class Configature::Namespace
53
54
  @extends = extends
54
55
  @env = extends&.instance_variable_get(:@env)
55
56
  @env_default = extends&.instance_variable_get(:@env_default)
56
- @namespaces = extends ? extends.namespaces.dup : { }
57
- @parameters = extends ? extends.parameters.dup : { }
57
+ @namespaces = extends&.namespaces&.dup || { }
58
+ @parameters = extends&.parameters&.dup || { }
58
59
  @env_suffix = env_suffix
59
60
  @env_name_prefix = name ? Configature::Support.extend_env_prefix(env_name_prefix, name) : ''
60
61
 
62
+ @config_name = extends&.config_name || name
63
+
61
64
  yield(self) if (block_given?)
62
65
  end
63
66
 
64
67
  def namespace(name, env_suffix: '', extends: nil, &block)
65
68
  name = name.to_sym
66
69
 
67
- @namespaces[name] = self.class.new(name, env_suffix: env_suffix, extends: extends && self.namespaces[extends], env_name_prefix: @env_name_prefix).tap do |n|
70
+ @namespaces[name] = self.class.new(
71
+ name,
72
+ env_suffix: env_suffix,
73
+ extends: extends && self.namespaces[extends],
74
+ env_name_prefix: @env_name_prefix
75
+ ).tap do |n|
68
76
  case (block&.arity)
69
77
  when nil
70
78
  nil
@@ -5,10 +5,9 @@ module Configature::Support
5
5
 
6
6
  def yaml_if_exist(path)
7
7
  return unless (File.exist?(path))
8
-
9
- # FIX: Use safe_load if safe_load supports aliases
8
+
10
9
  File.open(path) do |f|
11
- YAML.load(f)
10
+ YAML.safe_load(f, aliases: true) or { }
12
11
  end
13
12
  end
14
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: configature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Tadman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-25 00:00:00.000000000 Z
11
+ date: 2021-05-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Assists in the creation of config files from example templates and can
14
14
  identify when some customization is necessary.
@@ -63,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
63
  - !ruby/object:Gem::Version
64
64
  version: '0'
65
65
  requirements: []
66
- rubygems_version: 3.1.4
66
+ rubygems_version: 3.2.15
67
67
  signing_key:
68
68
  specification_version: 4
69
69
  summary: Configuration file auto-generator