Class: IsEmail::Diagnosis::Base Private

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/is_email/diagnosis/base.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An abstract superclass for all diagnoses

Direct Known Subclasses

CFWS, Deprecated, Invalid, RFC5321, RFC5322, Valid

Constant Summary collapse

DESCRIPTION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

""
ERROR_CODES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{}.freeze
MESSAGES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{}.freeze
REFERENCES =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ void

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.

Parameters:

  • type (String)


18
19
20
21
22
23
# File 'lib/is_email/diagnosis/base.rb', line 18

def initialize(type)
  @code = self.class::ERROR_CODES.fetch(type)
  @message = self.class::MESSAGES.fetch(type, "")
  @references = self.class::REFERENCES.fetch(type) { [] }.map { |ref| Reference.new(ref) }
  @type = type.to_s
end

Instance Attribute Details

#codeInteger (readonly)

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.

Returns:

  • (Integer)


26
27
28
# File 'lib/is_email/diagnosis/base.rb', line 26

def code
  @code
end

#messageString (readonly)

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.

Returns:

  • (String)


29
30
31
# File 'lib/is_email/diagnosis/base.rb', line 29

def message
  @message
end

#referencesArray<Reference> (readonly)

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.

Returns:



32
33
34
# File 'lib/is_email/diagnosis/base.rb', line 32

def references
  @references
end

#typeString (readonly)

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.

Returns:

  • (String)


35
36
37
# File 'lib/is_email/diagnosis/base.rb', line 35

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ -1, ...

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.

Allows sorting with Numerics and other diagnoses

Parameters:

  • other (Object)

Returns:

  • (-1, 0, 1, nil)


52
53
54
55
56
57
58
59
# File 'lib/is_email/diagnosis/base.rb', line 52

def <=>(other)
  case other
  when Base
    code <=> other.code
  when Numeric
    code <=> other
  end
end

#==(other) ⇒ Boolean Also known as: eql?

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.

Part of the [value object semantics] to make diagnoses equalable

[1]: thoughtbot.com/blog/value-object-semantics-in-ruby

Parameters:

  • other (Object)

Returns:

  • (Boolean)


43
44
45
# File 'lib/is_email/diagnosis/base.rb', line 43

def ==(other)
  other.instance_of?(self.class) && (self <=> other).zero?
end

#hashInteger

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.

Part of the [value object semantics] to make diagnoses equalable

[1]: thoughtbot.com/blog/value-object-semantics-in-ruby

Returns:

  • (Integer)


66
67
68
# File 'lib/is_email/diagnosis/base.rb', line 66

def hash
  [self.class, type].hash
end

#inspectString

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.

Returns:

  • (String)


71
72
73
# File 'lib/is_email/diagnosis/base.rb', line 71

def inspect
  "#<#{self.class.name}: #{type}>"
end