Sha256: 82235a27b48e895d2eea74cf245747c309e7b1f4103178b5f035cab6c6df0ac9

Contents?: true

Size: 803 Bytes

Versions: 3

Compression:

Stored size: 803 Bytes

Contents

# frozen_string_literal: true

require 'dry/initializer'
require 'dry/validation/constants'

module Dry
  module Validation
    # Abstract class for handling rule blocks
    #
    # @see Rule
    # @see Macro
    #
    # @api private
    class Function
      extend Dry::Initializer

      # @!attribute [r] block
      #   @return [Proc]
      #   @api private
      option :block

      private

      # Extract options for the block kwargs
      #
      # @return [Hash]
      #
      # @api private
      def block_options
        return EMPTY_HASH unless block

        @block_options ||= block
          .parameters
          .select { |arg| arg[0].equal?(:keyreq) }
          .map(&:last)
          .map { |name| [name, BLOCK_OPTIONS_MAPPINGS[name]] }
          .to_h
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dry-validation-1.1.1 lib/dry/validation/function.rb
dry-validation-1.1.0 lib/dry/validation/function.rb
dry-validation-1.0.0 lib/dry/validation/function.rb