Module: Axiom::Types::LengthComparable

Included in:
String, Symbol
Defined in:
lib/axiom/types/length_comparable.rb

Overview

Add a minimum and maximum length constraint to a type

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#rangeRange (readonly)

The range of allowed lengths

Returns:

  • (Range)


14
15
16
# File 'lib/axiom/types/length_comparable.rb', line 14

def range
  @range
end

Class Method Details

.extended(descendant) ⇒ undefined

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.

Hook called when module is extended

Add #minimum_length and #maximum_length DSL methods to descendant.

Parameters:

Returns:

  • (undefined)


25
26
27
28
29
30
31
32
# File 'lib/axiom/types/length_comparable.rb', line 25

def self.extended(descendant)
  super
  descendant.class_eval do
    accept_options :minimum_length, :maximum_length
    minimum_length Infinity.instance
    maximum_length NegativeInfinity.instance
  end
end

Instance Method Details

#finalizeAxiom::Types::LengthComparable

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.

Finalize by setting up a length range constraint



39
40
41
42
43
44
# File 'lib/axiom/types/length_comparable.rb', line 39

def finalize
  return self if frozen?
  @range = IceNine.deep_freeze(minimum_length..maximum_length)
  use_length_within_range
  super
end