Class: Reek::SmellWarning

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Comparable
Defined in:
lib/reek/smell_warning.rb

Overview

Reports a warning that a smell has been found.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(smell_type, context: '', lines:, message:, source:, parameters: {}) ⇒ SmellWarning

Note:

When using Reek's public API, you should not create SmellWarning objects yourself. This is why the initializer is not part of the public API.

Returns a new instance of SmellWarning.

Parameters:

  • smell_type (String)

    type of detected smell; corresponds to detector#smell_type

  • context (String) (defaults to: '')

    name of the context in which the smell occured

  • lines (Array<Integer>)

    list of lines on which the smell occured

  • message (String)

    text describing the smell in more detail

  • source (String)

    name of the source (e.g., the file name) in which the smell occured

  • parameters (Hash) (defaults to: {})

    smell-specific parameters


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/reek/smell_warning.rb', line 34

def initialize(smell_type, context: '', lines:, message:,
               source:, parameters: {})
  @smell_type = smell_type
  @source     = source
  @context    = context.to_s
  @lines      = lines
  @message    = message
  @parameters = parameters

  freeze
end

Instance Attribute Details

#contextObject (readonly)


18
19
20
# File 'lib/reek/smell_warning.rb', line 18

def context
  @context
end

#linesObject (readonly)


18
19
20
# File 'lib/reek/smell_warning.rb', line 18

def lines
  @lines
end

#messageObject (readonly)


18
19
20
# File 'lib/reek/smell_warning.rb', line 18

def message
  @message
end

#parametersObject (readonly)


18
19
20
# File 'lib/reek/smell_warning.rb', line 18

def parameters
  @parameters
end

#smell_typeObject (readonly)


18
19
20
# File 'lib/reek/smell_warning.rb', line 18

def smell_type
  @smell_type
end

#sourceObject (readonly)


18
19
20
# File 'lib/reek/smell_warning.rb', line 18

def source
  @source
end

Instance Method Details

#<=>(other) ⇒ Object


52
53
54
# File 'lib/reek/smell_warning.rb', line 52

def <=>(other)
  identifying_values <=> other.identifying_values
end

#base_hashObject (private)


87
88
89
90
91
92
93
94
95
# File 'lib/reek/smell_warning.rb', line 87

def base_hash
  {
    'context'    => context,
    'lines'      => lines,
    'message'    => message,
    'smell_type' => smell_type,
    'source'     => source
  }
end

#base_messageObject


71
72
73
# File 'lib/reek/smell_warning.rb', line 71

def base_message
  "#{smell_type}: #{context} #{message}"
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)

57
58
59
# File 'lib/reek/smell_warning.rb', line 57

def eql?(other)
  (self <=> other).zero?
end

75
76
77
# File 'lib/reek/smell_warning.rb', line 75

def explanatory_link
  DocumentationLink.build(smell_type)
end

#hashObject


47
48
49
# File 'lib/reek/smell_warning.rb', line 47

def hash
  identifying_values.hash
end

#to_hashObject


62
63
64
65
# File 'lib/reek/smell_warning.rb', line 62

def to_hash
  stringified_params = Hash[parameters.map { |key, val| [key.to_s, val] }]
  base_hash.merge(stringified_params)
end

#yaml_hashObject


67
68
69
# File 'lib/reek/smell_warning.rb', line 67

def yaml_hash
  to_hash.merge('documentation_link' => explanatory_link)
end