class Raygun::C5Conventions

Constants

ATTRIBUTION_HEADER
REPO
SOURCES

Attributes

sources[R]
target[R]

Public Class Methods

install(target:, sources: SOURCES) click to toggle source

Install the latest copy of c5-conventions rubocop config in the given directory. If the latest files can't be downloaded from GitHub, print a warning, don't raise an exception. Any existing .rubocop.yml will be overwritten.

# File lib/raygun/c5_conventions.rb, line 26
def self.install(target:, sources: SOURCES)
  new(target: target, sources: sources).install
rescue Errno::ENOENT, OpenURI::HTTPError => e
  puts ""
  puts "Failed to install the CarbonFive conventions from the #{REPO} GitHub repo".colorize(:light_red)
  puts "Error: #{e}".colorize(:light_red)
  puts "You'll have to manage your own `.rubocop.yml` setup".colorize(:light_red)
end
new(sources:, target:) click to toggle source
# File lib/raygun/c5_conventions.rb, line 35
def initialize(sources:, target:)
  @sources = sources
  @target = target
end

Public Instance Methods

install() click to toggle source
# File lib/raygun/c5_conventions.rb, line 40
def install
  sources.each do |url_str|
    uri = URI(url_str)
    contents = [attribution_header, uri.open.read].join("\n")
    filename = File.basename(uri.path)

    IO.write(File.join(target, filename), contents)
  end
end

Private Instance Methods

attribution_header() click to toggle source
# File lib/raygun/c5_conventions.rb, line 54
def attribution_header
  format(ATTRIBUTION_HEADER, sha: latest_commit_sha)
end
latest_commit_sha() click to toggle source
# File lib/raygun/c5_conventions.rb, line 58
def latest_commit_sha
  @latest_commit_sha ||= begin
    stdout = `git ls-remote https://github.com/#{REPO} main`
    stdout[/^(\h{7})/, 1] || "main"
  end
end