ultra_config 0.11.2 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/gem-push.yml +30 -0
- data/.github/workflows/ruby.yml +33 -0
- data/lib/ultra_config/config.rb +4 -2
- data/lib/ultra_config/namespace.rb +36 -3
- data/lib/ultra_config/validation.rb +12 -1
- data/ultra_config.gemspec +4 -3
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: effd42c60eb855e6b65f42a760674fc49d771ec0cb3dc4384e2aec26767335c0
|
4
|
+
data.tar.gz: 3fc7dd53bf2896d6544eecb8a888d20400ac93b29e5ca4d96bbe89f3605b28b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1a5f693f5f71e66b8b0e4cea0717b6a78b88eba48954c3ba9f4886812e58701d552cfe7e0dbda9f01f515eca1b2ec03741a954eb209847fdc031bd576487dd4
|
7
|
+
data.tar.gz: 9e0b2554883d638d695293d5b49a3a9a42b0408e1f34324e3fcc2a7065920905deffbe31435da230870f7570daedef1ede8ab1c0b7544c7aef54c62060f1031e
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
name: Build + Publish
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby 2.6
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.6.x
|
20
|
+
|
21
|
+
- name: Publish to RubyGems
|
22
|
+
run: |
|
23
|
+
mkdir -p $HOME/.gem
|
24
|
+
touch $HOME/.gem/credentials
|
25
|
+
chmod 0600 $HOME/.gem/credentials
|
26
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
27
|
+
gem build *.gemspec
|
28
|
+
gem push *.gem
|
29
|
+
env:
|
30
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -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
|
data/lib/ultra_config/config.rb
CHANGED
@@ -7,7 +7,9 @@ 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
15
|
@value = options[:default].nil? ? nil : options[:default]
|
@@ -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, @
|
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) unless v.nil?
|
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,7 +4,18 @@ module UltraConfig
|
|
4
4
|
module Validation
|
5
5
|
include Boolean
|
6
6
|
|
7
|
-
class ValidationError < StandardError
|
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)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
8
19
|
class TypeValidationError < ValidationError; end
|
9
20
|
|
10
21
|
def type_safety(type)
|
data/ultra_config.gemspec
CHANGED
@@ -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.
|
7
|
+
spec.version = '0.15.1'
|
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 "
|
23
|
-
spec.add_development_dependency "
|
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.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Kuruc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bump
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1
|
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
|
26
|
+
version: '0.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
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
|
@@ -59,6 +73,8 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
76
|
+
- ".github/workflows/gem-push.yml"
|
77
|
+
- ".github/workflows/ruby.yml"
|
62
78
|
- ".gitignore"
|
63
79
|
- Gemfile
|
64
80
|
- LICENSE.txt
|
@@ -90,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
106
|
- !ruby/object:Gem::Version
|
91
107
|
version: '0'
|
92
108
|
requirements: []
|
93
|
-
|
94
|
-
rubygems_version: 2.6.14
|
109
|
+
rubygems_version: 3.0.3
|
95
110
|
signing_key:
|
96
111
|
specification_version: 4
|
97
112
|
summary: Provides a simple way to define a configuration with validation
|