class ClosingComments::Source
Attributes
content[R]
path[R]
Public Class Methods
from(path:)
click to toggle source
# File lib/closing_comments/source.rb, line 11 def self.from(path:) new(path: path, content: File.read(path)) end
new(path:, content:)
click to toggle source
# File lib/closing_comments/source.rb, line 15 def initialize(path:, content:) @path = path @content = content end
Public Instance Methods
fix()
click to toggle source
# File lib/closing_comments/source.rb, line 32 def fix lines.map.with_index(1) { |default, no| fixes[no] || default }.join("\n") end
problematic?()
click to toggle source
# File lib/closing_comments/source.rb, line 20 def problematic? problems.count.positive? end
problems()
click to toggle source
# File lib/closing_comments/source.rb, line 24 def problems @problems ||= entities .reject(&:single_line?) .reject(&method(:commented?)) .map { |ent| Problem.new(ent, line(number: ent.last_line)) } end
Private Instance Methods
commented?(entity)
click to toggle source
This method reeks of :reek:FeatureEnvy (entity).
# File lib/closing_comments/source.rb, line 54 def commented?(entity) line(number: entity.last_line).end_with?(entity.ending) end
fixes()
click to toggle source
# File lib/closing_comments/source.rb, line 38 def fixes @fixes ||= problems .map { |problem| [problem.line, problem.fix] } .to_h end
line(number:)
click to toggle source
# File lib/closing_comments/source.rb, line 45 def line(number:) lines[number - 1] end
lines()
click to toggle source
# File lib/closing_comments/source.rb, line 49 def lines @lines ||= content.split("\n").push('') end
visitor()
click to toggle source
# File lib/closing_comments/source.rb, line 58 def visitor @visitor ||= visitor_class.new(content) end
visitor_class()
click to toggle source
# File lib/closing_comments/source.rb, line 62 def visitor_class path.end_with?('_spec.rb') ? Visitor::Spec : Visitor end