module Axiom::Types::ValueComparable

Add a minimum and maximum value constraint to a type

Public Class Methods

extended(descendant) click to toggle source

Hook called when module is extended

Add minimum and maximum DSL methods to descendant.

@param [Class<Axiom::Types::Type>] descendant

@return [undefined]

@api private

Calls superclass method
# File lib/axiom/types/value_comparable.rb, line 17
def self.extended(descendant)
  super
  descendant.class_eval do
    accept_options :minimum, :maximum
  end
end

Public Instance Methods

finalize() click to toggle source

Finalize by setting up a value range constraint

@return [Axiom::Types::ValueComparable]

@api private

Calls superclass method
# File lib/axiom/types/value_comparable.rb, line 29
def finalize
  return self if frozen?
  has_value_within_range
  super
end

Private Instance Methods

has_value_within_range() click to toggle source

Add a constraint for a value within a range

@return [undefined]

@todo freeze the minimum and maximum

@api private

# File lib/axiom/types/value_comparable.rb, line 44
def has_value_within_range
  range = minimum..maximum
  constraint(range.method(:cover?))
end