ultra_config 0.11.0 → 0.14.0

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
- SHA1:
3
- metadata.gz: 52234a8d4ae01dd19e6828c14d09a2af1acab2e3
4
- data.tar.gz: 2ad472cfa2349d68b08159f46794ffa6ca471cf5
2
+ SHA256:
3
+ metadata.gz: 0fdcef2c29aaf00fdacd4189c1b156e7308083d50061b58ec11ab26dd5f1aaf2
4
+ data.tar.gz: 52ecb944f849b9cc33e7913cc72e13e6802bfb34e77c64cd5876627f9bd3fb5d
5
5
  SHA512:
6
- metadata.gz: f195f6529ae3f645dee2e71535b22849b759763662f9b2675370fd020b0e92d77c834c857341c6042b66dfac270f24231b00899f79e582b3404b3f87652d8235
7
- data.tar.gz: b8f9d9b9bf802db40187d93865dd3e5414b97f165e7369357f03ef23f6321401241d6e969a570d10344d99c94d0588c779aa75dfa77557901812dd662911f1f5
6
+ metadata.gz: 89e667c687f45e8db12dcf5bfb2da6a1d03a2240adc337e5ab97f07d8256f00835a1bd1612738a25d89bca891e7259ea7243f70a8f6a39a2214a10c1ad88516e
7
+ data.tar.gz: 72b0d0d90766f0234e030f34bd44db68fcf9a45f5c2d257db5c1baa208fef8d5bf1990b818357e857570aafa97b067335970663575e6cf7e9fd375022c55efab
@@ -0,0 +1,33 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ master ]
13
+ pull_request:
14
+ branches: [ master ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
25
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
26
+ # uses: ruby/setup-ruby@v1
27
+ uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
28
+ with:
29
+ ruby-version: 2.6
30
+ - name: Install dependencies
31
+ run: bundle install
32
+ - name: Run tests
33
+ run: bundle exec rake
@@ -7,10 +7,12 @@ module UltraConfig
7
7
 
8
8
  attr_reader :value
9
9
 
10
- def initialize(options = {}, &block)
10
+ def initialize(name, parents, options = {}, &block)
11
+ @name = name
12
+ @parents = parents
11
13
  @config_block = block
12
14
 
13
- @value = options[:default] || nil
15
+ @value = options[:default].nil? ? nil : options[:default]
14
16
  @sanitize = options[:sanitize] || false
15
17
  @error_msg = options[:error_msg]
16
18
  end
@@ -21,7 +23,7 @@ module UltraConfig
21
23
  type_safety(Settings.type_safety) unless @type_safety_checked
22
24
  @value = @intermediate_value
23
25
  rescue UltraConfig::Validation::ValidationError
24
- raise UltraConfig::Validation::ValidationError.new(msg: @error_msg)
26
+ raise UltraConfig::Validation::ValidationError.new(@error_msg, @parents + [@name], sanitize? ? '*****' : @intermediate_value)
25
27
  ensure
26
28
  @type_safety_checked = false
27
29
  @intermediate_value = nil
@@ -1,13 +1,18 @@
1
+ require 'logger'
2
+
1
3
  require_relative 'config'
2
4
 
3
5
  module UltraConfig
4
6
  class Namespace
5
7
  class ObjectNotFoundError < StandardError; end
6
8
 
9
+ attr_accessor :logger
7
10
  attr_reader :objects
8
11
 
9
- def initialize(&block)
12
+ def initialize(parents = [], &block)
10
13
  @configuration = [block]
14
+ @parents = parents
15
+
11
16
  reset
12
17
  end
13
18
 
@@ -21,12 +26,12 @@ module UltraConfig
21
26
  end
22
27
 
23
28
  def namespace(name, &block)
24
- @objects[name] = Namespace.new(&block)
29
+ @objects[name] = Namespace.new(@parents + [name], &block)
25
30
  define_singleton_method(name) { @objects[name] }
26
31
  end
27
32
 
28
33
  def config(name, options = {}, &block)
29
- @objects[name] = Config.new(options, &block)
34
+ @objects[name] = Config.new(name, @parents, options, &block)
30
35
  define_singleton_method("#{name}=") { |value| @objects[name].value = value }
31
36
  define_singleton_method(name) { @objects[name].value }
32
37
  end
@@ -53,6 +58,21 @@ module UltraConfig
53
58
  hash
54
59
  end
55
60
 
61
+ def merge_hash!(hash, parents = [])
62
+ hash.each do |k, v|
63
+ options = send_chain(parents)
64
+ if options.objects[k.to_sym].is_a?(Config)
65
+ options.send("#{k}=", v)
66
+ elsif options.objects[k.to_sym].is_a?(Namespace)
67
+ merge_hash!(v, parents + [k])
68
+ else
69
+ logger.warn { "received an unknown config #{k} with value #{v} and parents: #{parents}" }
70
+ end
71
+ end
72
+
73
+ self
74
+ end
75
+
56
76
  def to_sanitized_h
57
77
  hash = {}
58
78
  @objects.each do |name, object|
@@ -73,5 +93,18 @@ module UltraConfig
73
93
  def method_missing(m)
74
94
  raise ObjectNotFoundError
75
95
  end
96
+
97
+ private
98
+
99
+ # Send a chain of methods to an object
100
+ # @param arr [Array] list of methods to send to object
101
+ # @return [Object] result of method chain
102
+ def send_chain(arr)
103
+ arr.inject(self) {|obj, arr| obj.send(arr) }
104
+ end
105
+
106
+ def logger
107
+ @logger ||= (logger || Logger.new(IO::NULL))
108
+ end
76
109
  end
77
110
  end
@@ -4,9 +4,15 @@ module UltraConfig
4
4
  module Validation
5
5
  include Boolean
6
6
 
7
- class ValidationError < StandardError;
8
- def initialize(msg: nil)
9
- super
7
+ class ValidationError < StandardError
8
+ attr_reader :config
9
+ attr_reader :value
10
+
11
+ def initialize(msg = nil, config = [], value = nil)
12
+ @value = value
13
+ @config = config.join('.')
14
+
15
+ super(msg)
10
16
  end
11
17
  end
12
18
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'ultra_config'
7
- spec.version = '0.11.0'
7
+ spec.version = '0.14.0'
8
8
  spec.authors = ['Gregory Kuruc']
9
9
  spec.email = ['gjk910327@gmail.com']
10
10
 
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
- spec.add_development_dependency "bundler", "~> 1.15"
23
- spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "bump", "~> 0.1"
23
+ spec.add_development_dependency "bundler", "~> 2.0"
24
+ spec.add_development_dependency "rake", ">= 12.3.3"
24
25
  spec.add_development_dependency "rspec", "~> 3.0"
25
26
  end
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ultra_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Kuruc
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-20 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: bump
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.15'
19
+ version: '0.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.15'
26
+ version: '0.1'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '2.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 12.3.3
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 12.3.3
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,13 +66,14 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '3.0'
55
- description:
69
+ description:
56
70
  email:
57
71
  - gjk910327@gmail.com
58
72
  executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
76
+ - ".github/workflows/ruby.yml"
62
77
  - ".gitignore"
63
78
  - Gemfile
64
79
  - LICENSE.txt
@@ -75,7 +90,7 @@ homepage: https://github.com/SpyMachine/UltraConfig
75
90
  licenses:
76
91
  - MIT
77
92
  metadata: {}
78
- post_install_message:
93
+ post_install_message:
79
94
  rdoc_options: []
80
95
  require_paths:
81
96
  - lib
@@ -90,9 +105,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
105
  - !ruby/object:Gem::Version
91
106
  version: '0'
92
107
  requirements: []
93
- rubyforge_project:
94
- rubygems_version: 2.6.14
95
- signing_key:
108
+ rubygems_version: 3.0.3
109
+ signing_key:
96
110
  specification_version: 4
97
111
  summary: Provides a simple way to define a configuration with validation
98
112
  test_files: []