Class: CucumberLint::LintedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cucumber_lint/linted_file.rb

Overview

A class that represents a file being linted

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LintedFile

Returns a new instance of LintedFile.



9
10
11
12
13
14
15
16
17
# File 'lib/cucumber_lint/linted_file.rb', line 9

def initialize path
  @path = Pathname.new path
  @content = IO.read path
  @lines = @content.lines

  @errors = []
  @fixes = {}
  @marked_for_deletion = false
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



7
8
9
# File 'lib/cucumber_lint/linted_file.rb', line 7

def content
  @content
end

#errorsObject (readonly)

Returns the value of attribute errors.



7
8
9
# File 'lib/cucumber_lint/linted_file.rb', line 7

def errors
  @errors
end

#linesObject (readonly)

Returns the value of attribute lines.



7
8
9
# File 'lib/cucumber_lint/linted_file.rb', line 7

def lines
  @lines
end

Instance Method Details

#add_error(error) ⇒ Object



20
21
22
# File 'lib/cucumber_lint/linted_file.rb', line 20

def add_error error
  @errors << "#{@path}:#{error}"
end

#add_fix(line_number, fix) ⇒ Object



25
26
27
28
# File 'lib/cucumber_lint/linted_file.rb', line 25

def add_fix line_number, fix
  @fixes[line_number] ||= []
  @fixes[line_number] += Array(fix)
end

#mark_for_deletionObject



31
32
33
# File 'lib/cucumber_lint/linted_file.rb', line 31

def mark_for_deletion
  @marked_for_deletion = true
end

#resolveObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cucumber_lint/linted_file.rb', line 36

def resolve
  if @marked_for_deletion
    delete
    :deleted
  elsif !errors.empty? || fixable?
    fix
    errors.empty? ? :written : :failed
  else
    :passed
  end
end