Module: Axiom::Types::ValueComparable

Included in:
Date, DateTime, Numeric, Time
Defined in:
lib/axiom/types/value_comparable.rb

Overview

Add a minimum and maximum value 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 values

Returns:

  • (Range)


14
15
16
# File 'lib/axiom/types/value_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 and #maximum DSL methods to descendant.

Parameters:

Returns:

  • (undefined)


25
26
27
28
# File 'lib/axiom/types/value_comparable.rb', line 25

def self.extended(descendant)
  super
  descendant.accept_options :minimum, :maximum
end

Instance Method Details

#finalizeAxiom::Types::ValueComparable

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 value range constraint



35
36
37
38
39
40
# File 'lib/axiom/types/value_comparable.rb', line 35

def finalize
  return self if frozen?
  @range = IceNine.deep_freeze(minimum..maximum)
  use_value_within_range
  super
end