Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dry-validation from dependencies #317

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ tmp
.keep
.rvmrc
.rakeTasks
.ruby-version
.sass-cache
Gemfile.lock
*.gem
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

7 changes: 3 additions & 4 deletions config.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$:.push File.expand_path('../lib', __FILE__)

require 'config/version'
require_relative 'lib/config/version'
require_relative 'lib/config/dry_validation_requirements'

Gem::Specification.new do |s|
s.name = 'config'
Expand All @@ -27,8 +26,8 @@ Donate: \e[34mhttps://opencollective.com/rubyconfig/donate\e[0m\n"
s.required_ruby_version = '>= 2.6.0'

s.add_dependency 'deep_merge', '~> 1.2', '>= 1.2.1'
s.add_dependency 'dry-validation', '~> 1.0', '>= 1.0.0'

s.add_development_dependency 'dry-validation', *Config::DRY_VALIDATION_REQUIREMENTS
s.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'

# Testing
Expand Down
2 changes: 1 addition & 1 deletion lib/config.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'config/compatibility'
require 'config/options'
require 'config/configuration'
require 'config/dry_validation_requirements'
require 'config/version'
require 'config/sources/yaml_source'
require 'config/sources/hash_source'
Expand Down
3 changes: 0 additions & 3 deletions lib/config/compatibility.rb

This file was deleted.

5 changes: 5 additions & 0 deletions lib/config/dry_validation_requirements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module Config
DRY_VALIDATION_REQUIREMENTS = ['~> 1.0', '>= 1.0.0'].freeze
end
4 changes: 4 additions & 0 deletions lib/config/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Config
class Error < StandardError
end
end
4 changes: 3 additions & 1 deletion lib/config/validation/error.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative "../error"

module Config
module Validation
class Error < StandardError
class Error < ::Config::Error

def self.format(v_res)
v_res.errors.group_by(&:path).map do |path, messages|
Expand Down
13 changes: 13 additions & 0 deletions lib/config/validation/schema.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require_relative '../dry_validation_requirements'
require_relative '../error'

module Config
module Validation
module Schema
Expand All @@ -8,6 +11,16 @@ def schema=(value)

def schema(&block)
if block_given?
begin
require 'dry/validation/version'
version = Gem::Version.new(Dry::Validation::VERSION)
unless ::Config::DRY_VALIDATION_REQUIREMENTS.all? { |req| Gem::Requirement.new(req).satisfied_by?(version) }
raise LoadError
end
rescue LoadError
raise ::Config::Error, 'Could not find a dry-validation version matching requirements' \
" (#{::Config::DRY_VALIDATION_REQUIREMENTS.map(&:inspect) * ','})"
end
# Delay require until optional schema validation is requested
require 'dry-validation'
@schema = Dry::Schema.define(&block)
Expand Down
8 changes: 4 additions & 4 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
##
# Load Rspec supporting files
#
Dir['./spec/support/**/*.rb'].each { |f| require f }
Dir['./spec/support/**/*.rb'].sort.each { |f| require f }

##
# Detect Rails/Sinatra dummy application based on gemfile name substituted by Appraisal
#
if ENV['APPRAISAL_INITIALIZED'] || ENV['GITHUB_ACTIONS']
app_name = Pathname.new(ENV['BUNDLE_GEMFILE']).basename.sub('.gemfile', '')
app_name = File.basename(ENV['BUNDLE_GEMFILE'], '.gemfile')
else
/.*?(?<app_name>rails.*?)\.gemfile/ =~ Dir["gemfiles/rails*.gemfile"].sort.last
end
Expand All @@ -33,7 +33,7 @@
case app_framework
when 'rails'
# Load Rails
require File.expand_path("../app/#{app_name}/config/environment", __FILE__)
require_relative "app/#{app_name}/config/environment"

APP_RAKEFILE = File.expand_path("../app/#{app_name}/Rakefile", __FILE__)

Expand All @@ -47,7 +47,7 @@

when 'sinatra'
# Load Sinatra
require File.expand_path("../app/#{app_name}/app", __FILE__)
require_relative "app/#{app_name}/app"

# Load Rspec
require 'rspec'
Expand Down