Module: Axiom::Attribute::LengthComparable

Includes:
Comparable
Included in:
String
Defined in:
lib/axiom/attribute/length_comparable.rb

Overview

A mixin for attributes that have comparable lengths

Instance Method Summary collapse

Methods included from Comparable

#asc, #desc, #range

Methods included from Function::Predicate::GreaterThan::Methods

#gt

Methods included from Function::Predicate::GreaterThanOrEqualTo::Methods

#gte

Methods included from Function::Predicate::LessThan::Methods

#lt

Methods included from Function::Predicate::LessThanOrEqualTo::Methods

#lte

Instance Method Details

#initialize(_name, options = EMPTY_HASH) ⇒ 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.

Initialize a length comparable attribute

Parameters:

  • _name (#to_sym)

    the attribute name

  • options (#to_hash) (defaults to: EMPTY_HASH)

    the options for the attribute

Options Hash (options):

  • :required (Boolean) — default: true

    if true, then the value cannot be nil

  • :minimum_length (::Integer)

    The minimum string length for a valid value

  • :maximum_length (::Integer)

    The maximum string length for a valid value

Returns:

  • (undefined)


26
27
28
29
30
31
32
33
34
35
# File 'lib/axiom/attribute/length_comparable.rb', line 26

def initialize(_name, options = EMPTY_HASH)
  super
  min, max = options.values_at(:minimum_length, :maximum_length)
  if min || max
    @type = type.new do
      minimum_length(min) if min
      maximum_length(max) if max
    end
  end
end