class Stannum::Contracts::MapContract::Builder
Builder
class for defining item constraints for a Contract
.
This class should not be invoked directly. Instead, pass a block to the constructor for HashContract
.
@api private
Public Instance Methods
key(property, constraint = nil, **options, &block)
click to toggle source
Defines a key constraint on the contract.
@overload key(key, constraint, **options)
Adds the given constraint to the contract for the value at the given key. @param key [String, Symbol, Array<String, Symbol>] The key to constrain. @param constraint [Stannum::Constraint::Base] The constraint to add. @param options [Hash<Symbol, Object>] Options for the constraint.
@overload key(**options) { |value| }
Creates a new Stannum::Constraint object with the given block, and adds that constraint to the contract for the value at the given key.
# File lib/stannum/contracts/map_contract.rb, line 90 def key(property, constraint = nil, **options, &block) self.constraint( constraint, property: property, property_type: :key, **options, &block ) end