config 5.2.0 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9473a6dc953514afb09fbefa950f14cf7fe20e9cf461740e682404dc06ea726
4
- data.tar.gz: 2dcd6fb8e88fbc2b04c152a424ad4877804e0c7e5607fc4d1b9be6000b02bf92
3
+ metadata.gz: 9695bee8465b0c65165242a23d7df19a04047c78d131587f87b5c0e356930a6c
4
+ data.tar.gz: 13b9ee27af8ad78c2450111854c1f8498b1019d0cd8c358eaa986bd0d01b8541
5
5
  SHA512:
6
- metadata.gz: '049ac670db93d0c93e7d3fe60688ae3edda405e9f28b67d2464d660ccd9a6dbbfd5d66e57d1d25b1b3fa763956d719e5fe252e7d5147e0bfc4da0f458b0f726f'
7
- data.tar.gz: 20774a5e9bfcbc377cd1969a133129b1259ccd9d211651312fce5e69a98999766ccb11ca1521e661f168086bfcd310f87840c141d2acd923b5fe708bf3fd8a26
6
+ metadata.gz: a15b3c5112f4f776f2df92d28fa4ac8d6d0dc92eeb294b863b0be055696d8a3cc7de4abbd44aab28cd31c9e2d716e8debbcae84a439758bd1ac9d5c4415da264
7
+ data.tar.gz: 65b04c96cf9e826fccceeff15a5897c19e2a617ab131922c1ab395dfe4aad8fe6320c5c5916b07f80c75c98369460cd9a252201d684da667a37a543edea4651e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.4.0
4
+
5
+ ### New features
6
+
7
+ * Add configuration option `environment` to override the use of `Rails.env` ([#356](https://github.com/rubyconfig/config/pull/356))
8
+
9
+ ## 5.3.0
10
+
11
+ * Remove `dry-validation` from dependencies ([#333](https://github.com/rubyconfig/config/pull/333))
12
+
3
13
  ## 5.2.0
4
14
 
5
15
  ### New features
data/README.md CHANGED
@@ -53,6 +53,8 @@ which will generate customizable config file `config/initializers/config.rb` and
53
53
 
54
54
  You can now edit them to adjust to your needs.
55
55
 
56
+ > Note: By default, the config environment will match the Rails environment (`Rails.env`). This can be changed by setting `config.environment`.
57
+
56
58
  ### Installing on Padrino
57
59
 
58
60
  Add the gem to your `Gemfile` and run `bundle install` to install it. Then edit `app.rb` and register `Config`
data/config.gemspec CHANGED
@@ -1,6 +1,5 @@
1
- $:.push File.expand_path('../lib', __FILE__)
2
-
3
- require 'config/version'
1
+ require_relative 'lib/config/version'
2
+ require_relative 'lib/config/dry_validation_requirements'
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = 'config'
@@ -32,8 +31,8 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
32
31
  s.required_ruby_version = '>= 2.6.0'
33
32
 
34
33
  s.add_dependency 'deep_merge', '~> 1.2', '>= 1.2.1'
35
- s.add_dependency 'dry-validation', '~> 1.0', '>= 1.0.0'
36
34
 
35
+ s.add_development_dependency 'dry-validation', *Config::DryValidationRequirements::VERSIONS
37
36
  s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
38
37
 
39
38
  # Testing
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Config
4
+ module DryValidationRequirements
5
+ VERSIONS = ['~> 1.0', '>= 1.0.0'].freeze
6
+
7
+ def self.load_dry_validation!
8
+ return if defined?(@load_dry_validation)
9
+
10
+ begin
11
+ require 'dry/validation/version'
12
+ version = Gem::Version.new(Dry::Validation::VERSION)
13
+ unless VERSIONS.all? { |req| Gem::Requirement.new(req).satisfied_by?(version) }
14
+ raise LoadError
15
+ end
16
+ rescue LoadError
17
+ raise ::Config::Error, 'Could not find a dry-validation version' \
18
+ ' matching requirements' \
19
+ " (#{VERSIONS.map(&:inspect) * ','})"
20
+ end
21
+
22
+ require 'dry/validation'
23
+ @load_dry_validation = true
24
+ nil
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ module Config
2
+ class Error < StandardError
3
+ end
4
+ end
@@ -9,7 +9,7 @@ module Config
9
9
 
10
10
  # Parse the settings before any of the initializers
11
11
  Config.load_and_set_settings(
12
- Config.setting_files(::Rails.root.join('config'), ::Rails.env)
12
+ Config.setting_files(::Rails.root.join('config'), Config.environment.nil? ? ::Rails.env : Config.environment.to_sym)
13
13
  )
14
14
  end
15
15
 
@@ -1,6 +1,8 @@
1
+ require_relative "../error"
2
+
1
3
  module Config
2
4
  module Validation
3
- class Error < StandardError
5
+ class Error < ::Config::Error
4
6
 
5
7
  def self.format(v_res)
6
8
  v_res.errors.group_by(&:path).map do |path, messages|
@@ -1,3 +1,6 @@
1
+ require_relative '../dry_validation_requirements'
2
+ require_relative '../error'
3
+
1
4
  module Config
2
5
  module Validation
3
6
  module Schema
@@ -9,7 +12,7 @@ module Config
9
12
  def schema(&block)
10
13
  if block_given?
11
14
  # Delay require until optional schema validation is requested
12
- require 'dry-validation'
15
+ Config::DryValidationRequirements.load_dry_validation!
13
16
  @schema = Dry::Schema.define(&block)
14
17
  else
15
18
  @schema
@@ -4,6 +4,10 @@ module Config
4
4
  module Validation
5
5
  module Validate
6
6
  def validate!
7
+ return unless Config.validation_contract || Config.schema
8
+
9
+ Config::DryValidationRequirements.load_dry_validation!
10
+
7
11
  validate_using!(Config.validation_contract)
8
12
  validate_using!(Config.schema)
9
13
  end
@@ -1,3 +1,3 @@
1
1
  module Config
2
- VERSION = '5.2.0'.freeze
2
+ VERSION = '5.4.0'.freeze
3
3
  end
data/lib/config.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'config/compatibility'
2
1
  require 'config/options'
3
2
  require 'config/configuration'
3
+ require 'config/dry_validation_requirements'
4
4
  require 'config/version'
5
5
  require 'config/sources/yaml_source'
6
6
  require 'config/sources/hash_source'
@@ -27,7 +27,8 @@ module Config
27
27
  overwrite_arrays: true,
28
28
  merge_hash_arrays: false,
29
29
  validation_contract: nil,
30
- evaluate_erb_in_yaml: true
30
+ evaluate_erb_in_yaml: true,
31
+ environment: nil
31
32
  )
32
33
 
33
34
  def self.setup
@@ -15,6 +15,11 @@ Config.setup do |config|
15
15
  #
16
16
  # config.overwrite_arrays = true
17
17
 
18
+ # Defines current environment, affecting which settings file will be loaded.
19
+ # Default: `Rails.env`
20
+ #
21
+ # config.environment = ENV.fetch('ENVIRONMENT', :development)
22
+
18
23
  # Load environment variables from the `ENV` object and override any settings defined in files.
19
24
  #
20
25
  # config.use_env = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kuczynski
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-03-01 00:00:00.000000000 Z
13
+ date: 2024-03-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: deep_merge
@@ -42,7 +42,7 @@ dependencies:
42
42
  - - ">="
43
43
  - !ruby/object:Gem::Version
44
44
  version: 1.0.0
45
- type: :runtime
45
+ type: :development
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
@@ -236,8 +236,9 @@ files:
236
236
  - README.md
237
237
  - config.gemspec
238
238
  - lib/config.rb
239
- - lib/config/compatibility.rb
240
239
  - lib/config/configuration.rb
240
+ - lib/config/dry_validation_requirements.rb
241
+ - lib/config/error.rb
241
242
  - lib/config/integrations/heroku.rb
242
243
  - lib/config/integrations/rails/railtie.rb
243
244
  - lib/config/integrations/sinatra.rb
@@ -1,3 +0,0 @@
1
- if defined?(RbConfig) && defined?(Config)
2
- Object.send :remove_const, :Config
3
- end