Class: Slimembedcop::Offense
- Inherits:
-
Object
- Object
- Slimembedcop::Offense
- Extended by:
- Forwardable
- Defined in:
- lib/slimembedcop/offense.rb
Overview
Wraps a RuboCop offense.
Instance Attribute Summary collapse
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path, offset, offense, source) ⇒ Offense
constructor
A new instance of Offense.
- #location ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(hash) ⇒ Object
Constructor Details
#initialize(path, offset, offense, source) ⇒ Offense
21 22 23 24 25 26 |
# File 'lib/slimembedcop/offense.rb', line 21 def initialize(path, offset, offense, source) @path = path @offset = offset @offense = offense @source = source end |
Instance Attribute Details
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
13 14 15 |
# File 'lib/slimembedcop/offense.rb', line 13 def offset @offset end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/slimembedcop/offense.rb', line 13 def path @path end |
Instance Method Details
#location ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/slimembedcop/offense.rb', line 28 def location @location ||= ::Parser::Source::Range.new( buffer, @offense.location.begin_pos + @offset, @offense.location.end_pos + @offset ) end |
#marshal_dump ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/slimembedcop/offense.rb', line 36 def marshal_dump { begin_pos: @offense.location.begin_pos, cop_name: @offense.cop_name, end_pos: @offense.location.end_pos, path: @path, message: @offense..dup.force_encoding(::Encoding::UTF_8).scrub, offset: @offset, severity: @offense.severity.to_s, source: @source, status: @offense.status } end |
#marshal_load(hash) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/slimembedcop/offense.rb', line 50 def marshal_load(hash) @path = hash[:path] @offset = hash[:offset] @offense = ::RuboCop::Cop::Offense.new( hash[:severity], ::Parser::Source::Range.new( ::Parser::Source::Buffer.new( @path, source: @source ), hash[:begin_pos], hash[:end_pos] ), hash[:message], hash[:cop_name], hash[:status].to_sym ) @source = hash[:source] end |