Sha256: aaa80e76f52aec6897f0346def79e950ef9d4ee71fdacde64fef5a9187cf270d
Contents?: true
Size: 1.26 KB
Versions: 6
Compression:
Stored size: 1.26 KB
Contents
# frozen_string_literal: true class Serega module SeregaPlugins module If # # Validator for attribute :unless option # class CheckOptUnless class << self # # Checks attribute :unless option that must be [nil, Symbol, Proc, #call] # # @param opts [Hash] Attribute options # # @raise [SeregaError] Attribute validation error # # @return [void] # def call(opts) return unless opts.key?(:unless) check_type(opts[:unless]) end private def check_type(value) return if value.is_a?(Symbol) raise SeregaError, must_be_callable unless value.respond_to?(:call) SeregaValidations::Utils::CheckExtraKeywordArg.call(value, ":unless option") params_count = SeregaUtils::ParamsCount.call(value, max_count: 2) if params_count > 2 raise SeregaError, "Option :unless value should have up to 2 parameters (object, context)" end end def must_be_callable "Invalid attribute option :unless. It must be a Symbol, a Proc or respond to :call" end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems