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_detector, options = {}) ⇒ SmellWarning


13
14
15
16
17
18
19
# File 'lib/reek/smell_warning.rb', line 13

def initialize(smell_detector, options = {})
  self.smell_detector = smell_detector
  self.context        = options.fetch(:context, '').to_s
  self.lines          = options.fetch(:lines)
  self.message        = options.fetch(:message)
  self.parameters     = options.fetch(:parameters, {})
end

Instance Attribute Details

#contextObject

Returns the value of attribute context


10
11
12
# File 'lib/reek/smell_warning.rb', line 10

def context
  @context
end

#linesObject

Returns the value of attribute lines


10
11
12
# File 'lib/reek/smell_warning.rb', line 10

def lines
  @lines
end

#messageObject

Returns the value of attribute message


10
11
12
# File 'lib/reek/smell_warning.rb', line 10

def message
  @message
end

#parametersObject

Returns the value of attribute parameters


10
11
12
# File 'lib/reek/smell_warning.rb', line 10

def parameters
  @parameters
end

#smell_detectorObject

Returns the value of attribute smell_detector


10
11
12
# File 'lib/reek/smell_warning.rb', line 10

def smell_detector
  @smell_detector
end

Instance Method Details

#<=>(other) ⇒ Object


29
30
31
# File 'lib/reek/smell_warning.rb', line 29

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

#encode_with(coder) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/reek/smell_warning.rb', line 45

def encode_with(coder)
  coder.tag = nil
  coder['smell_category']  = smell_detector.smell_category
  coder['smell_type']      = smell_detector.smell_type
  coder['source']          = smell_detector.source
  coder['context']         = context
  coder['lines']           = lines
  coder['message']         = message
  parameters.each do |key, value|
    coder[key.to_s] = value
  end
end

#eql?(other) ⇒ Boolean


33
34
35
# File 'lib/reek/smell_warning.rb', line 33

def eql?(other)
  (self <=> other) == 0
end

#hashObject


25
26
27
# File 'lib/reek/smell_warning.rb', line 25

def hash
  sort_key.hash
end

#matches?(klass, patterns) ⇒ Boolean


37
38
39
# File 'lib/reek/smell_warning.rb', line 37

def matches?(klass, patterns)
  smell_classes.include?(klass.to_s) && contains_all?(patterns)
end

#report_on(listener) ⇒ Object


41
42
43
# File 'lib/reek/smell_warning.rb', line 41

def report_on(listener)
  listener.found_smell(self)
end

#smell_classesObject


21
22
23
# File 'lib/reek/smell_warning.rb', line 21

def smell_classes
  [smell_detector.smell_category, smell_detector.smell_type]
end