Class: Aequitas::Rule::PrimitiveType

Inherits:
Aequitas::Rule show all
Defined in:
lib/aequitas/rule/primitive_type.rb,
lib/aequitas/rule/primitive_type/virtus.rb

Direct Known Subclasses

Virtus

Defined Under Namespace

Classes: Virtus

Instance Attribute Summary collapse

Attributes inherited from Aequitas::Rule

#attribute_name, #custom_message, #guard, #skip_condition

Attributes included from ValueObject

#equalizer

Instance Method Summary collapse

Methods inherited from Aequitas::Rule

#attribute_value, #execute?, rules_for, #skip?, #validate, #violation_info, #violation_values

Methods included from ValueObject

#equalize_on

Constructor Details

#initialize(attribute_name, options = {}) ⇒ PrimitiveType

Returns a new instance of PrimitiveType



11
12
13
14
15
# File 'lib/aequitas/rule/primitive_type.rb', line 11

def initialize(attribute_name, options = {})
  super

  @primitive = options.fetch(:primitive)
end

Instance Attribute Details

#primitiveObject (readonly)

Returns the value of attribute primitive



9
10
11
# File 'lib/aequitas/rule/primitive_type.rb', line 9

def primitive
  @primitive
end

Instance Method Details

#expected_type?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/aequitas/rule/primitive_type.rb', line 21

def expected_type?(value)
  value.is_a?(primitive)
end

#valid_value?(value) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/aequitas/rule/primitive_type.rb', line 17

def valid_value?(value)
  skip?(value) || expected_type?(value)
end

#violation_dataObject



29
30
31
# File 'lib/aequitas/rule/primitive_type.rb', line 29

def violation_data
  [ [ :primitive, primitive ] ]
end

#violation_typeObject



25
26
27
# File 'lib/aequitas/rule/primitive_type.rb', line 25

def violation_type
  :primitive
end