ultra_config 0.12.0 → 0.15.2

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: 58a62bd2b4590fb7d00e698c1bd3514773eb7de8
4
- data.tar.gz: 10fbaa211096cc69a4ee95a40ecf01ed5d2536e5
2
+ SHA256:
3
+ metadata.gz: 1b37b43ab37d62c4b959206d3e2324a6164f6079bb7c8fcb7e9b7815cc6fef70
4
+ data.tar.gz: b482dbf18dab4065656de6fd0ca0b22961d5671fce9ef7e208d89b41116535f9
5
5
  SHA512:
6
- metadata.gz: 164325f002a4eead14d033410e0aacdd72c6eb8e962c9de84d8c4999e0ff22b6009cfbbec91e4a05c1bf2d163ebe653979fda80b5c644a788ba77518b61ecfa2
7
- data.tar.gz: 7b53809a1b08a2cee51941080eae2b879f0ae0c953417db076f631c74ceab49e9556720eebe05117ca541e4150e7293664a4c5053adc803b2fef45d33e016e9b
6
+ metadata.gz: e063ae5be2ff060d1a14511400c1a49d4d8d15fc090962d1aa7ac079790c40e4a3648624ec0e2b3d4de6ec380d71cc16ee826de6a14170a211a33cf1fc763bc5
7
+ data.tar.gz: 27863a05d64c93df679026b34c06427173ae2445a8f42bb8cc519ac6ba93f52cf8787cf43057b173d0ab27b38be3311a381761dd4e9c74546a93063434bff56f
@@ -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
@@ -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.new(@error_msg, sanitize? ? '*****' : @intermediate_value)
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
@@ -8,8 +8,9 @@ module UltraConfig
8
8
  attr_reader :config
9
9
  attr_reader :value
10
10
 
11
- def initialize(msg = nil, value = nil)
11
+ def initialize(msg = nil, config = [], value = nil)
12
12
  @value = value
13
+ @config = config.join('.')
13
14
 
14
15
  super(msg)
15
16
  end
@@ -24,6 +25,9 @@ module UltraConfig
24
25
  return if @value.nil?
25
26
  return if @value.is_a?(Boolean) && @intermediate_value.is_a?(Boolean)
26
27
 
28
+ # Be nice and convert Strings to Symbols
29
+ @intermediate_value = @intermediate_value.to_sym if @intermediate_value.is_a?(String) && @value.is_a?(Symbol)
30
+
27
31
  raise TypeValidationError if @value.class != @intermediate_value.class
28
32
  end
29
33
 
@@ -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.12.0'
7
+ spec.version = '0.15.2'
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.12.0
4
+ version: 0.15.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Kuruc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-23 00:00:00.000000000 Z
11
+ date: 2020-08-18 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
@@ -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
- rubyforge_project:
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