Sha256: 0d8a79f2aee3337ed53a21dc4860acaeb93c5efac4676e707822fbb70533887a
Contents?: true
Size: 1.03 KB
Versions: 1
Compression:
Stored size: 1.03 KB
Contents
# frozen_string_literal: true module Kind module Validator DEFAULT_STRATEGIES = Set.new(%w[instance_of kind_of is_a]).freeze class InvalidDefinition < ArgumentError OPTIONS = 'Options to define one: :of, :instance_of, :respond_to, :klass, :array_of or :array_with'.freeze def initialize(attribute) super "invalid type definition for :#{attribute} attribute. #{OPTIONS}" end private_constant :OPTIONS end class InvalidDefaultStrategy < ArgumentError OPTIONS = DEFAULT_STRATEGIES.map { |option| ":#{option}" }.join(', ') def initialize(option) super "#{option.inspect} is an invalid option. Please use one of these: #{OPTIONS}" end private_constant :OPTIONS end def self.default_strategy @default_strategy ||= :kind_of end def self.default_strategy=(option) if DEFAULT_STRATEGIES.member?(String(option)) @default_strategy = option.to_sym else raise InvalidDefaultStrategy.new(option) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
kind-1.9.0 | lib/kind/validator.rb |