Class: Txray::SourceFile
- Inherits:
-
Object
- Object
- Txray::SourceFile
- Defined in:
- lib/txray/source_file.rb
Constant Summary collapse
- DIRECTIVE =
/\A#\s*txray:(?<action>disable|enable)\b(?<rules>[\w,\s-]*)/
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #disabled?(line, rule_id) ⇒ Boolean
-
#initialize(path:, root:, comments: [], code: "") ⇒ SourceFile
constructor
A new instance of SourceFile.
Constructor Details
#initialize(path:, root:, comments: [], code: "") ⇒ SourceFile
Returns a new instance of SourceFile.
19 20 21 22 23 24 25 26 |
# File 'lib/txray/source_file.rb', line 19 def initialize(path:, root:, comments: [], code: "") @path = path @root = root @lines = code.lines @inline = {} @regions = [] index(comments) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/txray/source_file.rb', line 7 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/txray/source_file.rb', line 7 def root @root end |
Class Method Details
.parse(path, code: nil) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/txray/source_file.rb', line 9 def self.parse(path, code: nil) code ||= File.read(path) result = Prism.parse(code) return nil if result.failure? new(path: path, root: result.value, comments: result.comments, code: code) rescue StandardError nil end |
Instance Method Details
#disabled?(line, rule_id) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/txray/source_file.rb', line 28 def disabled?(line, rule_id) return true if covers?(@inline[line], rule_id) @regions.any? { |region| line.between?(region[:from], region[:to]) && covers?(region[:rules], rule_id) } end |