class Supercop::Actions::FileInjector

Attributes

filename[R]
line[R]

Public Class Methods

new(filename:, line:) click to toggle source
# File lib/supercop/actions/file_injector.rb, line 6
def initialize(filename:, line:)
  @filename = filename
  @line = line
end

Public Instance Methods

call() click to toggle source
# File lib/supercop/actions/file_injector.rb, line 11
def call
  return if file_include?

  insert_into_file
end
file_include?() click to toggle source
# File lib/supercop/actions/file_injector.rb, line 17
def file_include?
  File.foreach(filename).grep(sanitized).present?
end

Private Instance Methods

insert_into_file() click to toggle source
# File lib/supercop/actions/file_injector.rb, line 24
def insert_into_file
  File.open(filename, 'a') do |f|
    f.write(line)
  end
end
sanitized() click to toggle source
# File lib/supercop/actions/file_injector.rb, line 30
def sanitized
  line.sub(/\s\n$/, '')
end