Class: Rubomop::TodoFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rubomop/todo_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename:) ⇒ TodoFile

Returns a new instance of TodoFile.



6
7
8
# File 'lib/rubomop/todo_file.rb', line 6

def initialize(filename:)
  @filename = filename
end

Instance Attribute Details

#copsObject

Returns the value of attribute cops.



4
5
6
# File 'lib/rubomop/todo_file.rb', line 4

def cops
  @cops
end

#filenameObject (readonly)

Returns the value of attribute filename.



3
4
5
# File 'lib/rubomop/todo_file.rb', line 3

def filename
  @filename
end

#headerObject

Returns the value of attribute header.



4
5
6
# File 'lib/rubomop/todo_file.rb', line 4

def header
  @header
end

#raw_linesObject

Returns the value of attribute raw_lines.



4
5
6
# File 'lib/rubomop/todo_file.rb', line 4

def raw_lines
  @raw_lines
end

Instance Method Details

#active_copsObject



21
22
23
# File 'lib/rubomop/todo_file.rb', line 21

def active_cops
  cops.select { _1.active? }
end

#cop_for(name) ⇒ Object



17
18
19
# File 'lib/rubomop/todo_file.rb', line 17

def cop_for(name)
  cops.select { _1.name == name }.first
end

#outputObject



35
36
37
# File 'lib/rubomop/todo_file.rb', line 35

def output
  output_lines.join("\n") + "\n"
end

#output_linesObject



25
26
27
28
29
30
31
32
33
# File 'lib/rubomop/todo_file.rb', line 25

def output_lines
  result = header.map(&:chomp)
  result << ""
  active_cops.each do |cop|
    result += cop.output_lines
    result << ""
  end
  result[0..-2]
end

#parseObject



10
11
12
13
14
15
# File 'lib/rubomop/todo_file.rb', line 10

def parse
  self.raw_lines = File.readlines(filename)
  self.header, *raw_tasks = raw_lines.split("\n")
  self.cops = raw_tasks.map { Cop.create_and_parse(_1) }
  self
end

#save!Object



39
40
41
42
# File 'lib/rubomop/todo_file.rb', line 39

def save!
  FileUtils.rm_f(filename)
  File.write(filename, output || "")
end