Class: Type::Definition::Collection

Inherits:
Object
  • Object
show all
Includes:
Type::Definition
Defined in:
lib/type/definition/collection.rb,
lib/type/definition/collection/constrained.rb

Overview

Re-open Collection to add constraint methods

Direct Known Subclasses

Constrained

Defined Under Namespace

Classes: Constrained

Instance Attribute Summary

Attributes included from Type::Definition

#name

Instance Method Summary collapse

Methods included from Type::Definition

included, #initialize, #nilable, #nilable?, #refine, #to_proc, #to_s

Instance Method Details

#cast!(input, &block) ⇒ Object

Raises:



25
26
27
28
# File 'lib/type/definition/collection.rb', line 25

def cast!(input, &block)
  raise CastError.new(input, self) unless input.kind_of?(Enumerable)
  super
end

#constrain(constraint) ⇒ Type::Defintion::Collection::Constrained #constrain(constraint) ⇒ Type::Defintion::Collection::Constrained Also known as: of

Overloads:

  • #constrain(constraint) ⇒ Type::Defintion::Collection::Constrained

    Parameters:

  • #constrain(constraint) ⇒ Type::Defintion::Collection::Constrained

    Parameters:

    • constraint (Hash{Type::Defintion=>Type::Defintion})

      a single-element hash whose key is the constraint for keys, and whose value is a constraint for values

Returns:

  • (Type::Defintion::Collection::Constrained)


14
15
16
# File 'lib/type/definition/collection/constrained.rb', line 14

def constrain(constraint)
  Constrained.new(self, constraint)
end

#constrained?False

Returns:

  • (False)


20
21
22
# File 'lib/type/definition/collection/constrained.rb', line 20

def constrained?
  false
end

#valid?(input, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/type/definition/collection.rb', line 20

def valid?(input, *args, &block)
  return false unless input.kind_of?(Enumerable)
  super
end