dry-rb / dry-logic

Predicate logic with rule composition
https://dry-rb.org/gems/dry-logic/
MIT License
179 stars 66 forks source link

Fix instance_of? checks called on schema instance in dry-v #35

Closed flash-gordon closed 7 years ago

flash-gordon commented 7 years ago

@solnic ping me if you have any comments on this, this allows for passing injected deps into externally defined predicates

example code from dry-v

module IssuesPredicate
  include Dry::Logic::Predicates

  predicate(:equipment_exists?) do |account, value|
    account.include?(value)
  end
end

Schema = Dry::Validation.Schema do
  configure do
    option :account
    predicates(::IssuesPredicate)
  end

  optional(:equipment_ids).each { equipment_exists?(account) }
end

/cc @NikitaNaumenko