I know this sound a lot like an xkcd://1172: Every change breaks someone’s workflow, but I can try to don’t.
While I was trying to formulate a Proof of concept of a bug related to Dry-Validation I though it was a good idea to spin my local Guard and start iterating my case using an new spec file (and being sure I didn’t break some other spec also). When I tried to use Guard got this error:
Users/esparta/.rvm/gems/ruby-2.2.9@dry-rb/gems/guard-rspec-4.7.3/lib/guard/rspec_defaults.rb:1:in `<top (required)>': Guard is not a module (TypeError)
Going deep on this, turns out Dry Validation defines a class called Guard, specifically Dry::Validation::Guard
in lib/dry/validation/schema_compiler.rb
, since is a class, Guard gem cannot work as intended because expect to be a module.
Is there any chance to rename the conflicting class to something like Dry::Validation::InternalGuard
? The following diff made possible to continue working with Guard as expected:
diff --git a/lib/dry/validation/executor.rb b/lib/dry/validation/executor.rb │
index 330be83..11ab58e 100644 │
--- a/lib/dry/validation/executor.rb │
+++ b/lib/dry/validation/executor.rb │
@@ -45,7 +45,7 @@ module Dry │
def call(input, result) │
rules.each_with_object(result) do |(name, checks), hash| │
checks.each do |check| │
- check_res = check.is_a?(Guard) ? check.(input, result) : check.(input) │
+ check_res = check.is_a?(InternalGuard) ? check.(input, result) : check.(input) │
if hash.key?(name) │
if hash[name].is_a?(Array) │
hash[name] << check_res
diff --git a/lib/dry/validation/schema_compiler.rb b/lib/dry/validation/schema_compiler.rb │
index 240345b..1878093 100644 │
--- a/lib/dry/validation/schema_compiler.rb │
+++ b/lib/dry/validation/schema_compiler.rb │
@@ -2,7 +2,7 @@ require 'dry/logic/rule_compiler' │
│
module Dry │
module Validation │
- class Guard │
+ class InternalGuard │
attr_reader :rule, :deps │
│
def initialize(rule, deps) │
@@ -70,7 +70,7 @@ module Dry │
│
def visit_guard(node) │
deps, other = node │
- Guard.new(visit(other), deps) │
+ InternalGuard.new(visit(other), deps) │
end │
│
def visit_type(type)
Of course I’d understand if this is not possible.