File tree 11 files changed +51
-15
lines changed
11 files changed +51
-15
lines changed Original file line number Diff line number Diff line change 12
12
.keep
13
13
.rvmrc
14
14
.rakeTasks
15
+ .ruby-version
15
16
.sass-cache
16
17
Gemfile.lock
17
18
* .gem
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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'
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
1
+ module Config
2
+ class Error < StandardError
3
+ end
4
+ end
Original file line number Diff line number Diff line change
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 |
Original file line number Diff line number Diff line change
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 @@ def schema=(value)
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
Original file line number Diff line number Diff line change @@ -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
Original file line number Diff line number Diff line change 14
14
##
15
15
# Load Rspec supporting files
16
16
#
17
- Dir [ './spec/support/**/*.rb' ] . each { |f | require f }
17
+ Dir [ './spec/support/**/*.rb' ] . sort . each { |f | require f }
18
18
19
19
##
20
20
# Detect Rails/Sinatra dummy application based on gemfile name substituted by Appraisal
21
21
#
22
22
if ENV [ 'APPRAISAL_INITIALIZED' ] || ENV [ 'GITHUB_ACTIONS' ]
23
- app_name = Pathname . new ( ENV [ 'BUNDLE_GEMFILE' ] ) . basename . sub ( '.gemfile' , '' )
23
+ app_name = File . basename ( ENV [ 'BUNDLE_GEMFILE' ] , '.gemfile ' )
24
24
else
25
25
/.*?(?<app_name>rails.*?)\. gemfile/ =~ Dir [ "gemfiles/rails*.gemfile" ] . sort . last
26
26
end
33
33
case app_framework
34
34
when 'rails'
35
35
# Load Rails
36
- require File . expand_path ( "../ app/#{ app_name } /config/environment", __FILE__ )
36
+ require_relative " app/#{ app_name } /config/environment"
37
37
38
38
APP_RAKEFILE = File . expand_path ( "../app/#{ app_name } /Rakefile" , __FILE__ )
39
39
47
47
48
48
when 'sinatra'
49
49
# Load Sinatra
50
- require File . expand_path ( "../ app/#{ app_name } /app", __FILE__ )
50
+ require_relative " app/#{ app_name } /app"
51
51
52
52
# Load Rspec
53
53
require 'rspec'
You can’t perform that action at this time.
0 commit comments