Class: Stannum::Contracts::MapContract::Builder Private

Inherits:
Stannum::Contract::Builder show all
Defined in:
lib/stannum/contracts/map_contract.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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.

Instance Method Summary collapse

Methods inherited from Stannum::Contract::Builder

#property

Instance Method Details

#key(key, constraint, **options) ⇒ Object #key(**options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Defines a key constraint on the contract.

Overloads:

  • #key(key, constraint, **options) ⇒ Object

    Adds the given constraint to the contract for the value at the given key.

    Parameters:

    • key (String, Symbol, Array<String, Symbol>)

      The key to constrain.

    • constraint (Stannum::Constraint::Base)

      The constraint to add.

    • options (Hash<Symbol, Object>)

      Options for the constraint.

  • #key(**options) ⇒ Object

    Creates a new Stannum::Constraint object with the given block, and adds that constraint to the contract for the value at the given key.



90
91
92
93
94
95
96
97
98
# 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