These are chat archives for dry-rb/chat

25th
Aug 2017
Nikita Naumenko
@NikitaNaumenko
Aug 25 2017 18:22

Good evening, please tell me, if I put the predicate into a separate file for this validation

 schema.rb
IssueSchema < Dry::Validation.Schema(BaseSchema)
  configure do
    option :account
    predicates(::IssuesPredicate)
   end

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

issue_predicate.rb

module IssuesPredicate
  include Dry::Logic::Predicates

  predicate(:equipment_exists?) do |account, value|
    account.equipments.where(sequential_id: value).exists?
  end

I get the error

 + account + is not a valid predicate name

but if I declare this predicate inside configure

      configure do
        option :account
        predicates(::IssuesPredicate)
        def equipment_exists?(value)
          account.equipments.where(sequential_id: value).exists?
        end
        optional(:equipment_ids).maybe(:array?) { each(equipment_exists?: account) }

      end

everything will work fine (also there are such predicates with Arguments only without everyone and they work well) what could be the reason for such behavior, am I doing something wrong?