Class: Aequitas::Rule::Length::Equal

Inherits:
Aequitas::Rule::Length show all
Defined in:
lib/aequitas/rule/length/equal.rb

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::Length

rules_for, #valid_value?, #value_length

Methods inherited from Aequitas::Rule

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

Methods included from ValueObject

#equalize_on

Constructor Details

- (Equal) initialize(attribute_name, options)



14
15
16
17
18
# File 'lib/aequitas/rule/length/equal.rb', line 14

def initialize(attribute_name, options)
  super

  @expected = options.fetch(:expected)
end

Instance Attribute Details

- (Object) expected (readonly)

Returns the value of attribute expected



12
13
14
# File 'lib/aequitas/rule/length/equal.rb', line 12

def expected
  @expected
end

Instance Method Details

- (String?) expected_length?(length)

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.

Validate the value length is equal to the expected length



37
38
39
# File 'lib/aequitas/rule/length/equal.rb', line 37

def expected_length?(length)
  expected == length
end

- (Object) violation_data



24
25
26
# File 'lib/aequitas/rule/length/equal.rb', line 24

def violation_data
  [ [ :expected, expected ] ]
end

- (Object) violation_type



20
21
22
# File 'lib/aequitas/rule/length/equal.rb', line 20

def violation_type
  :wrong_length
end