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

- (PrimitiveType) initialize(attribute_name, options = {})



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

- (Object) primitive (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

- (Boolean) expected_type?(value)



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

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

- (Boolean) valid_value?(value)



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

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

- (Object) violation_data



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

def violation_data
  [ [ :primitive, primitive ] ]
end

- (Object) violation_type



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

def violation_type
  :primitive
end