These are chat archives for dry-rb/chat

19th
Jan 2018
Lance Carlson
@lancecarlson
Jan 19 2018 00:29
Do you know if value(included_in?) can be an option field?
I'm having issues marking it optional
Piotr Solnica
@solnic
Jan 19 2018 08:33
@lancecarlson optional as in, the value could be nil, or optional as in they key could be omitted?
Kevin Ross
@rosskevin
Jan 19 2018 19:44

I've got a strange problem with a high-level rule - it always fails on then or > with

NoMethodError: undefined method `>' for ["^Yes", "No"]:Array
module Types
  include Dry::Types.module
  Type = Types::Strict::String.default('text').enum('checkbox', 'date', 'number', 'radio', 'select', 'select_dynamic', 'text')
end


QUESTION_SCHEMA = Dry::Validation.Schema do
  configure do
    def has_default_option?(options)
      true
    end

    def requires_options?(type)
      true
    end
  end

  optional(:options).each(:str?)
  required(:type).filled(Types::Type)

  rule(valid_options: [:type, :options]) do |type, options|
    type.requires_options? > (options.filled? & options.gt?(1) & options.has_default_option?)
  end
end

It is called with: {options: ['^Yes', 'No'], type: 'radio'}

This is very close to the high-level rules example, so not sure what I'm doing wrong here. Thoughts?