Class: Raygun::C5Conventions

Inherits:
Object
  • Object
show all
Defined in:
lib/raygun/c5_conventions.rb

Constant Summary collapse

REPO =
"carbonfive/c5-conventions".freeze
SOURCES =
[
  "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop.yml",
  "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-common.yml",
  "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-performance.yml",
  "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-rails.yml",
  "https://raw.githubusercontent.com/#{REPO}/main/rubocop/.rubocop-rspec.yml"
].freeze
ATTRIBUTION_HEADER =
"# Sourced from \#{REPO} @ %<sha>s\n#\n# If you make changes to this file, consider opening a PR to backport them to the c5-conventions repo:\n# https://github.com/\#{REPO}\n"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources:, target:) ⇒ C5Conventions

Returns a new instance of C5Conventions.



35
36
37
38
# File 'lib/raygun/c5_conventions.rb', line 35

def initialize(sources:, target:)
  @sources = sources
  @target = target
end

Class Method Details

.install(target:, sources: SOURCES) ⇒ Object

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.



26
27
28
29
30
31
32
33
# 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

Instance Method Details

#installObject



40
41
42
43
44
45
46
47
48
# 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