Sha256: 8ffed9158680ef5e9cb4537cb20dcc8b217d3a3390799df7bca3f4179bf50290
Contents?: true
Size: 1.05 KB
Versions: 20
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true class Serega module SeregaValidations module Attribute # # Attribute `:serializer` option validator # class CheckOptSerializer class << self # # Checks attribute :serializer option # # @param opts [Hash] Attribute options # # @raise [SeregaError] SeregaError that option has invalid value # # @return [void] # def call(opts) return unless opts.key?(:serializer) value = opts[:serializer] return if valid_serializer?(value) raise SeregaError, "Invalid option :serializer => #{value.inspect}." \ " Can be a Serega subclass, a String or a Proc without arguments" end private def valid_serializer?(value) value.is_a?(String) || (value.is_a?(Proc) && (value.parameters.count == 0)) || (value.is_a?(Class) && (value < Serega)) end end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems