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, lines:, message:, source:, context: '', 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
# File 'lib/reek/smell_warning.rb', line 34

def initialize(smell_type, lines:, message:, source:, context: '', 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



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

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

#base_hashObject (private)



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

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

#base_messageObject



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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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


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

def explanatory_link
  DocumentationLink.build(smell_type)
end

#hashObject



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

def hash
  identifying_values.hash
end

#to_hashObject



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

def to_hash
  stringified_params = parameters.transform_keys(&:to_s)
  base_hash.merge(stringified_params)
end

#yaml_hashObject



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

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