Class: Lumin::Offense

Inherits:
Object
  • Object
show all
Defined in:
lib/lumin/offense.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, location:, rule_name:, message:, correctable: false, safe: true, source_line: nil, correction: nil) ⇒ Offense

Returns a new instance of Offense.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/lumin/offense.rb', line 9

def initialize(path:, location:, rule_name:, message:, correctable: false, safe: true, source_line: nil,
               correction: nil)
  @path = path.to_s.freeze
  @location = Astel::Location.from(location)
  @rule_name = rule_name.to_s.freeze
  @message = message.to_s.freeze
  @correctable = correctable
  @safe = safe
  @source_line = source_line&.freeze
  @correction = correction
end

Instance Attribute Details

#correctionObject (readonly)

Returns the value of attribute correction.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def correction
  @correction
end

#locationObject (readonly)

Returns the value of attribute location.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def location
  @location
end

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def message
  @message
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def path
  @path
end

#rule_nameObject (readonly)

Returns the value of attribute rule_name.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def rule_name
  @rule_name
end

#safeObject (readonly)

Returns the value of attribute safe.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def safe
  @safe
end

#source_lineObject (readonly)

Returns the value of attribute source_line.



7
8
9
# File 'lib/lumin/offense.rb', line 7

def source_line
  @source_line
end

Instance Method Details

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



41
42
43
# File 'lib/lumin/offense.rb', line 41

def ==(other)
  other.is_a?(self.class) && to_h == other.to_h
end

#correctable?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/lumin/offense.rb', line 21

def correctable?
  @correctable
end

#hashObject



46
47
48
# File 'lib/lumin/offense.rb', line 46

def hash
  to_h.hash
end

#marshal_dumpObject



50
51
52
# File 'lib/lumin/offense.rb', line 50

def marshal_dump
  to_h
end

#marshal_load(attributes) ⇒ Object



54
55
56
# File 'lib/lumin/offense.rb', line 54

def marshal_load(attributes)
  initialize(**attributes)
end

#to_hObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/lumin/offense.rb', line 29

def to_h
  {
    path: path,
    location: location,
    rule_name: rule_name,
    message: message,
    correctable: correctable?,
    safe: safe,
    source_line: source_line
  }
end

#with_path(path) ⇒ Object



25
26
27
# File 'lib/lumin/offense.rb', line 25

def with_path(path)
  self.class.new(**to_h.merge(path: path))
end