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

#primitive?(value) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/aequitas/rule/primitive_type.rb', line 23

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

#valid?(resource) ⇒ Boolean

Returns:

  • (Boolean)


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

def valid?(resource)
  value = attribute_value(resource)

  skip?(value) || primitive?(value)
end

#violation_data(resource) ⇒ Object



31
32
33
# File 'lib/aequitas/rule/primitive_type.rb', line 31

def violation_data(resource)
  [ [ :primitive, primitive ] ]
end

#violation_type(resource) ⇒ Object



27
28
29
# File 'lib/aequitas/rule/primitive_type.rb', line 27

def violation_type(resource)
  :primitive
end