Module: RASN1::Types::Constrained::ClassMethods

Included in:
RASN1::Types::Constrained
Defined in:
lib/rasn1/types/constrained.rb

Overview

Define class/module methods for RASN1::Types::Constrained module

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#constraintProc

Returns proc to check constraints.

Returns:

  • (Proc)

    proc to check constraints



13
14
15
# File 'lib/rasn1/types/constrained.rb', line 13

def constraint
  @constraint
end

Instance Method Details

#check_constraint(value) ⇒ Object

Check constraint, if defined

Parameters:

  • value (Object)

    the value of the type to check

Raises:



24
25
26
27
# File 'lib/rasn1/types/constrained.rb', line 24

def check_constraint(value)
  return unless constrained?
  raise ConstraintError.new(self) unless @constraint.call(value)
end

#constrained?Boolean

Check if a constraint is really defined

Returns:



17
18
19
# File 'lib/rasn1/types/constrained.rb', line 17

def constrained?
  @constraint.is_a?(Proc)
end