raygun 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/raygun CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- File.expand_path('../../lib', __FILE__).tap do |lib|
3
+ File.expand_path("../lib", __dir__).tap do |lib|
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  end
6
6
 
7
- require 'raygun/raygun'
7
+ require "raygun/raygun"
8
8
 
9
9
  raygun = Raygun::Runner.parse(ARGV)
10
10
 
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -5,41 +5,40 @@
5
5
  # want to add a gem dependency.
6
6
 
7
7
  class String
8
-
9
8
  #
10
9
  # Colors Hash
11
10
  #
12
11
  COLORS = {
13
- :black => 0,
14
- :red => 1,
15
- :green => 2,
16
- :yellow => 3,
17
- :blue => 4,
18
- :magenta => 5,
19
- :cyan => 6,
20
- :white => 7,
21
- :default => 9,
22
-
23
- :light_black => 10,
24
- :light_red => 11,
25
- :light_green => 12,
26
- :light_yellow => 13,
27
- :light_blue => 14,
28
- :light_magenta => 15,
29
- :light_cyan => 16,
30
- :light_white => 17
12
+ black: 0,
13
+ red: 1,
14
+ green: 2,
15
+ yellow: 3,
16
+ blue: 4,
17
+ magenta: 5,
18
+ cyan: 6,
19
+ white: 7,
20
+ default: 9,
21
+
22
+ light_black: 10,
23
+ light_red: 11,
24
+ light_green: 12,
25
+ light_yellow: 13,
26
+ light_blue: 14,
27
+ light_magenta: 15,
28
+ light_cyan: 16,
29
+ light_white: 17
31
30
  }
32
31
 
33
32
  #
34
33
  # Modes Hash
35
34
  #
36
35
  MODES = {
37
- :default => 0, # Turn off all attributes
36
+ default: 0, # Turn off all attributes
38
37
  #:bright => 1, # Set bright mode
39
- :underline => 4, # Set underline mode
40
- :blink => 5, # Set blink mode
41
- :swap => 7, # Exchange foreground and background colors
42
- :hide => 8 # Hide text (foreground color would be the same as background)
38
+ underline: 4, # Set underline mode
39
+ blink: 5, # Set blink mode
40
+ swap: 7, # Exchange foreground and background colors
41
+ hide: 8 # Hide text (foreground color would be the same as background)
43
42
  }
44
43
 
45
44
  protected
@@ -47,16 +46,14 @@ class String
47
46
  #
48
47
  # Set color values in new string intance
49
48
  #
50
- def set_color_parameters( params )
51
- if (params.instance_of?(Hash))
52
- @color = params[:color]
53
- @background = params[:background]
54
- @mode = params[:mode]
55
- @uncolorized = params[:uncolorized]
56
- self
57
- else
58
- nil
59
- end
49
+ def color_parameters(params)
50
+ return unless params.instance_of?(Hash)
51
+
52
+ @color = params[:color]
53
+ @background = params[:background]
54
+ @mode = params[:mode]
55
+ @uncolorized = params[:uncolorized]
56
+ self
60
57
  end
61
58
 
62
59
  public
@@ -77,22 +74,23 @@ class String
77
74
  # puts "This is blue text on red".blue.on_red.blink
78
75
  # puts "This is uncolorized".blue.on_red.uncolorize
79
76
  #
80
- def colorize( params )
77
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
78
+ def colorize(params)
81
79
  return self unless STDOUT.isatty
82
80
 
83
81
  begin
84
- require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
82
+ require "Win32/Console/ANSI" if RUBY_PLATFORM.match?(/win32/)
85
83
  rescue LoadError
86
- raise 'You must gem install win32console to use colorize on Windows'
84
+ raise "You must gem install win32console to use colorize on Windows"
87
85
  end
88
86
 
89
87
  color_parameters = {}
90
88
 
91
- if (params.instance_of?(Hash))
89
+ if params.instance_of?(Hash)
92
90
  color_parameters[:color] = COLORS[params[:color]]
93
91
  color_parameters[:background] = COLORS[params[:background]]
94
92
  color_parameters[:mode] = MODES[params[:mode]]
95
- elsif (params.instance_of?(Symbol))
93
+ elsif params.instance_of?(Symbol)
96
94
  color_parameters[:color] = COLORS[params]
97
95
  end
98
96
 
@@ -100,15 +98,18 @@ class String
100
98
  color_parameters[:background] ||= @background ||= COLORS[:default]
101
99
  color_parameters[:mode] ||= @mode ||= MODES[:default]
102
100
 
103
- color_parameters[:uncolorized] ||= @uncolorized ||= self.dup
101
+ color_parameters[:uncolorized] ||= @uncolorized ||= dup
104
102
 
105
103
  # calculate bright mode
106
104
  color_parameters[:color] += 50 if color_parameters[:color] > 10
107
105
 
108
106
  color_parameters[:background] += 50 if color_parameters[:background] > 10
109
107
 
110
- "\033[#{color_parameters[:mode]};#{color_parameters[:color]+30};#{color_parameters[:background]+40}m#{color_parameters[:uncolorized]}\033[0m".set_color_parameters( color_parameters )
108
+ "\033[#{color_parameters[:mode]};#{color_parameters[:color] + 30};"\
109
+ "#{color_parameters[:background] + 40}m#{color_parameters[:uncolorized]}\033[0m"\
110
+ .color_parameters(color_parameters)
111
111
  end
112
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
112
113
 
113
114
  #
114
115
  # Return uncolorized string
@@ -127,37 +128,36 @@ class String
127
128
  #
128
129
  # Make some color and on_color methods
129
130
  #
130
- COLORS.each_key do | key |
131
+ COLORS.each_key do |key|
131
132
  next if key == :default
132
133
 
133
134
  define_method key do
134
- self.colorize( :color => key )
135
+ colorize(color: key)
135
136
  end
136
137
 
137
138
  define_method "on_#{key}" do
138
- self.colorize( :background => key )
139
+ colorize(background: key)
139
140
  end
140
141
  end
141
142
 
142
143
  #
143
144
  # Methods for modes
144
145
  #
145
- MODES.each_key do | key |
146
+ MODES.each_key do |key|
146
147
  next if key == :default
147
148
 
148
149
  define_method key do
149
- self.colorize( :mode => key )
150
+ colorize(mode: key)
150
151
  end
151
152
  end
152
153
 
153
154
  class << self
154
-
155
155
  #
156
156
  # Return array of available modes used by colorize method
157
157
  #
158
158
  def modes
159
159
  keys = []
160
- MODES.each_key do | key |
160
+ MODES.each_key do |key|
161
161
  keys << key
162
162
  end
163
163
  keys
@@ -168,7 +168,7 @@ class String
168
168
  #
169
169
  def colors
170
170
  keys = []
171
- COLORS.each_key do | key |
171
+ COLORS.each_key do |key|
172
172
  keys << key
173
173
  end
174
174
  keys
@@ -177,16 +177,16 @@ class String
177
177
  #
178
178
  # Display color matrix with color names.
179
179
  #
180
- def color_matrix( txt = "[X]" )
180
+ def color_matrix(txt = "[X]")
181
181
  size = String.colors.length
182
- String.colors.each do | color |
183
- String.colors.each do | back |
184
- print txt.colorize( :color => color, :background => back )
182
+ String.colors.each do |color|
183
+ String.colors.each do |back|
184
+ print txt.colorize(color: color, background: back)
185
185
  end
186
186
  puts " < #{color}"
187
187
  end
188
- String.colors.reverse.each_with_index do | back, index |
189
- puts "#{"|".rjust(txt.length)*(size-index)} < #{back}"
188
+ String.colors.reverse.each_with_index do |back, index|
189
+ puts "#{"|".rjust(txt.length) * (size - index)} < #{back}"
190
190
  end
191
191
  ""
192
192
  end
@@ -1,43 +1,47 @@
1
- require 'optparse'
2
- require 'ostruct'
3
- require 'fileutils'
4
- require 'securerandom'
5
- require 'net/http'
6
- require 'json'
7
- require 'colorize'
8
-
9
- require_relative 'version'
1
+ require "optparse"
2
+ require "ostruct"
3
+ require "fileutils"
4
+ require "securerandom"
5
+ require "net/http"
6
+ require "open-uri"
7
+ require "json"
8
+ require "colorize"
9
+
10
+ require_relative "version"
11
+ require_relative "template_repo"
10
12
 
11
13
  module Raygun
12
14
  class Runner
13
- CARBONFIVE_REPO = 'carbonfive/raygun-rails'
15
+ CARBONFIVE_REPO = "carbonfive/raygun-rails"
16
+ C5_CONVENTIONS_REPO = "carbonfive/c5-conventions"
14
17
 
15
- attr_accessor :target_dir, :app_dir, :app_name, :dash_name, :snake_name, :camel_name, :title_name, :prototype_repo,
18
+ attr_accessor :target_dir, :app_dir, :app_name, :dash_name, :snake_name,
19
+ :camel_name, :title_name, :prototype_repo,
16
20
  :current_ruby_version, :current_ruby_patch_level
17
21
 
18
22
  def initialize(target_dir, prototype_repo)
19
23
  @target_dir = target_dir
20
24
  @app_dir = File.expand_path(target_dir.strip.to_s)
21
- @app_name = File.basename(app_dir).gsub(/\s+/, '-')
22
- @dash_name = app_name.gsub('_', '-')
23
- @snake_name = app_name.gsub('-', '_')
25
+ @app_name = File.basename(app_dir).gsub(/\s+/, "-")
26
+ @dash_name = app_name.tr("_", "-")
27
+ @snake_name = app_name.tr("-", "_")
24
28
  @camel_name = camelize(snake_name)
25
29
  @title_name = titleize(snake_name)
26
30
  @prototype_repo = prototype_repo
27
31
 
28
32
  @current_ruby_version = RUBY_VERSION
29
- @current_ruby_patch_level = if RUBY_VERSION < '2.1.0' # Ruby adopted semver starting with 2.1.0.
30
- "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
33
+ @current_ruby_patch_level = if RUBY_VERSION < "2.1.0" # Ruby adopted semver starting with 2.1.0.
34
+ "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
31
35
  else
32
- "#{RUBY_VERSION}"
36
+ RUBY_VERSION.to_s
33
37
  end
34
38
  end
35
39
 
36
40
  def check_target
37
- unless Dir["#{@app_dir}/*"].empty?
38
- puts "Misfire! The target directory isn't empty... aim elsewhere."
39
- exit 1
40
- end
41
+ return if Dir["#{@app_dir}/*"].empty?
42
+
43
+ puts "Misfire! The target directory isn't empty... aim elsewhere.".colorize(:light_red)
44
+ exit 1
41
45
  end
42
46
 
43
47
  def fetch_prototype
@@ -45,26 +49,26 @@ module Raygun
45
49
  $stdout.flush
46
50
 
47
51
  # Check if we can connect, or fail gracefully and use the latest cached version.
48
- latest_tag_obj = fetch_latest_tag(prototype_repo)
49
- latest_tag = latest_tag_obj['name']
50
- tarball_url = latest_tag_obj['tarball_url']
52
+ repo = TemplateRepo.new(prototype_repo)
53
+ name = repo.name
54
+ tarball_url = repo.tarball
55
+ sha = repo.sha
51
56
 
52
- print " #{latest_tag}.".colorize(:white)
57
+ print " #{name}.".colorize(:white)
53
58
  $stdout.flush
54
59
 
55
60
  cached_prototypes_dir = File.join(Dir.home, ".raygun")
56
- @prototype = "#{cached_prototypes_dir}/#{prototype_repo.sub('/', '--')}-#{latest_tag}.tar.gz"
61
+ @prototype = "#{cached_prototypes_dir}/#{name.gsub("/", "--")}-#{sha}.tar.gz"
57
62
 
58
63
  # Do we already have the tarball cached under ~/.raygun?
59
- if File.exists?(@prototype)
64
+ if File.exist?(@prototype)
60
65
  puts " Using cached version.".colorize(:yellow)
61
66
  else
62
67
  print " Downloading...".colorize(:yellow)
63
68
  $stdout.flush
64
69
 
65
70
  # Download the tarball and install in the cache.
66
- Dir.mkdir(cached_prototypes_dir, 0755) unless Dir.exists?(cached_prototypes_dir)
67
-
71
+ Dir.mkdir(cached_prototypes_dir, 0o755) unless Dir.exist?(cached_prototypes_dir)
68
72
  shell "curl -s -L #{tarball_url} -o #{@prototype}"
69
73
  puts " done!".colorize(:yellow)
70
74
  end
@@ -72,50 +76,56 @@ module Raygun
72
76
 
73
77
  def check_raygun_version
74
78
  required_raygun_version =
75
- %x{tar xfz #{@prototype} --include "*.raygun-version" -O 2> /dev/null}.chomp ||
76
- ::Raygun::VERSION
77
-
78
- if Gem::Version.new(required_raygun_version) > Gem::Version.new(::Raygun::VERSION)
79
- puts ""
80
- print "Hold up!".colorize(:red)
81
- print " This version of the raygun gem (".colorize(:light_red)
82
- print "#{::Raygun::VERSION})".colorize(:white)
83
- print " is too old to generate this application (needs ".colorize(:light_red)
84
- print "#{required_raygun_version}".colorize(:white)
85
- puts " or newer).".colorize(:light_red)
86
- puts ""
87
- print "Please update the gem by running ".colorize(:light_red)
88
- print "gem update raygun".colorize(:white)
89
- puts ", and try again. Thanks!".colorize(:light_red)
90
- puts ""
91
- exit 1
92
- end
79
+ `tar xfz #{@prototype} --include "*.raygun-version" -O 2> /dev/null`.chomp ||
80
+ ::Raygun::VERSION
81
+ return unless Gem::Version.new(required_raygun_version) > Gem::Version.new(::Raygun::VERSION)
82
+
83
+ puts ""
84
+ print "Hold up!".colorize(:red)
85
+ print " This version of the raygun gem (".colorize(:light_red)
86
+ print "#{::Raygun::VERSION})".colorize(:white)
87
+ print " is too old to generate this application (needs ".colorize(:light_red)
88
+ print required_raygun_version.to_s.colorize(:white)
89
+ puts " or newer).".colorize(:light_red)
90
+ puts ""
91
+ print "Please update the gem by running ".colorize(:light_red)
92
+ print "gem update raygun".colorize(:white)
93
+ puts ", and try again. Thanks!".colorize(:light_red)
94
+ puts ""
95
+ exit 1
93
96
  end
94
97
 
95
98
  def copy_prototype
96
99
  FileUtils.mkdir_p(app_dir)
97
100
 
98
- shell "tar xfz #{@prototype} -C #{app_dir}"
101
+ shell "tar xfz #{@prototype} -C \"#{app_dir}\""
99
102
 
100
103
  # Github includes an extra directory layer in the tag tarball.
101
104
  extraneous_dir = Dir.glob("#{app_dir}/*").first
102
105
  dirs_to_move = Dir.glob("#{extraneous_dir}/*", File::FNM_DOTMATCH)
103
- .reject { |d| %w{. ..}.include?(File.basename(d)) }
106
+ .reject { |d| %w[. ..].include?(File.basename(d)) }
104
107
 
105
108
  FileUtils.mv dirs_to_move, app_dir
106
109
  FileUtils.remove_dir extraneous_dir
110
+
111
+ fetch_rubocop_file if @prototype_repo == CARBONFIVE_REPO
107
112
  end
108
113
 
109
114
  def rename_new_app
110
115
  Dir.chdir(app_dir) do
111
116
  {
112
- 'AppPrototype' => camel_name,
113
- 'app-prototype' => dash_name,
114
- 'app_prototype' => snake_name,
115
- 'App Prototype' => title_name
117
+ "AppPrototype" => camel_name,
118
+ "app-prototype" => dash_name,
119
+ "app_prototype" => snake_name,
120
+ "App Prototype" => title_name
116
121
  }.each do |proto_name, new_name|
117
122
  shell "find . -type f -print | xargs #{sed_i} 's/#{proto_name}/#{new_name}/g'"
118
123
  end
124
+
125
+ %w[d f].each do |find_type|
126
+ shell "find . -depth -type #{find_type} -name '*app_prototype*' " \
127
+ "-exec bash -c 'mv $0 ${0/app_prototype/#{snake_name}}' {} \\;"
128
+ end
119
129
  end
120
130
  end
121
131
 
@@ -144,26 +154,33 @@ module Raygun
144
154
  def initialize_git
145
155
  Dir.chdir(app_dir) do
146
156
  shell "git init"
157
+ shell "git checkout -q -b main"
147
158
  shell "git add -A ."
148
159
  shell "git commit -m 'Raygun-zapped skeleton.'"
149
160
  end
150
161
  end
151
162
 
163
+ # rubocop:disable Metrics/AbcSize
152
164
  def print_plan
153
- puts ' ____ '.colorize(:light_yellow)
165
+ puts " ____ ".colorize(:light_yellow)
154
166
  puts ' / __ \____ ___ ______ ___ ______ '.colorize(:light_yellow)
155
167
  puts ' / /_/ / __ `/ / / / __ `/ / / / __ \ '.colorize(:light_yellow)
156
- puts ' / _, _/ /_/ / /_/ / /_/ / /_/ / / / / '.colorize(:light_yellow)
168
+ puts " / _, _/ /_/ / /_/ / /_/ / /_/ / / / / ".colorize(:light_yellow)
157
169
  puts ' /_/ |_|\__,_/\__, /\__, /\__,_/_/ /_/ '.colorize(:light_yellow)
158
- puts ' /____//____/ '.colorize(:light_yellow)
170
+ puts " /____//____/ ".colorize(:light_yellow)
159
171
  puts
160
- puts "Raygun will create new app in directory:".colorize(:yellow) + " #{target_dir}".colorize(:yellow) + "...".colorize(:yellow)
172
+ puts "Raygun will create new app in directory:".colorize(:yellow) +
173
+ " #{target_dir}".colorize(:yellow) + "...".colorize(:yellow)
161
174
  puts
162
- puts "-".colorize(:blue) + " Application Name:".colorize(:light_blue) + " #{title_name}".colorize(:light_reen)
163
- puts "-".colorize(:blue) + " Project Template:".colorize(:light_blue) + " #{prototype_repo}".colorize(:light_reen)
164
- puts "-".colorize(:blue) + " Ruby Version: ".colorize(:light_blue) + " #{@current_ruby_patch_level}".colorize(:light_reen)
175
+ puts "-".colorize(:blue) + " Application Name:".colorize(:light_blue) +
176
+ " #{title_name}".colorize(:light_reen)
177
+ puts "-".colorize(:blue) + " Project Template:".colorize(:light_blue) +
178
+ " #{prototype_repo}".colorize(:light_reen)
179
+ puts "-".colorize(:blue) + " Ruby Version: ".colorize(:light_blue) +
180
+ " #{@current_ruby_patch_level}".colorize(:light_reen)
165
181
  puts
166
182
  end
183
+ # rubocop:enable Metrics/AbcSize
167
184
 
168
185
  def print_next_steps
169
186
  if @prototype_repo == CARBONFIVE_REPO
@@ -172,25 +189,30 @@ module Raygun
172
189
  print_next_steps_for_custom_repo
173
190
  end
174
191
  end
175
-
192
+
193
+ # rubocop:disable Metrics/AbcSize
176
194
  def print_next_steps_carbon_five
177
195
  puts ""
178
196
  puts "Zap! Your application is ready. Next steps...".colorize(:yellow)
179
197
  puts ""
180
198
  puts "# Install updated dependencies and prepare the database".colorize(:light_green)
181
199
  puts "$".colorize(:blue) + " cd #{target_dir}".colorize(:light_blue)
182
- puts "$".colorize(:blue) + " ./bin/setup".colorize(:light_blue)
200
+ puts "$".colorize(:blue) + " bin/setup".colorize(:light_blue)
183
201
  puts ""
184
202
  puts "# Run the specs (they should all pass)".colorize(:light_green)
185
- puts "$".colorize(:blue) + " rake".colorize(:light_blue)
203
+ puts "$".colorize(:blue) + " bin/rake".colorize(:light_blue)
186
204
  puts ""
187
205
  puts "# Run the app and check things out".colorize(:light_green)
188
- puts "$".colorize(:blue) + " foreman start".colorize(:light_blue)
206
+ puts "$".colorize(:blue) + " yarn start".colorize(:light_blue)
189
207
  puts "$".colorize(:blue) + " open http://localhost:3000".colorize(:light_blue)
190
208
  puts ""
209
+ puts "# For next steps like adding Bootstrap or React, check out the raygun README".colorize(:light_green)
210
+ puts "$".colorize(:blue) + " open https://github.com/carbonfive/raygun/#next-steps".colorize(:light_blue)
211
+ puts ""
191
212
  puts "Enjoy your Carbon Five flavored Rails application!".colorize(:yellow)
192
213
  end
193
-
214
+ # rubocop:enable Metrics/AbcSize
215
+
194
216
  def print_next_steps_for_custom_repo
195
217
  puts ""
196
218
  puts "Zap! Your application is ready.".colorize(:yellow)
@@ -200,111 +222,104 @@ module Raygun
200
222
 
201
223
  protected
202
224
 
203
- # Fetch the tags for the repo (e.g. 'carbonfive/raygun-rails') and return the latest as JSON.
204
- def fetch_latest_tag(repo)
205
- url = "https://api.github.com/repos/#{repo}/tags"
206
- uri = URI.parse(url)
207
- http = Net::HTTP.new(uri.host, uri.port)
208
- http.use_ssl = true
209
- request = Net::HTTP::Get.new(URI.encode(url))
210
-
211
- response = http.request(request)
212
-
213
- unless response.code == "200"
214
- puts ""
215
- print "Whoops - need to try again!".colorize(:red)
216
- puts ""
217
- print "We could not find (".colorize(:light_red)
218
- print "#{repo}".colorize(:white)
219
- print ") on github.".colorize(:light_red)
220
- puts ""
221
- print "The response from github was a (".colorize(:light_red)
222
- print "#{response.code}".colorize(:white)
223
- puts ") which I'm sure you can fix right up!".colorize(:light_red)
224
- puts ""
225
- exit 1
226
- end
225
+ def fetch_rubocop_file
226
+ sha = shell("git ls-remote https://github.com/#{C5_CONVENTIONS_REPO} master") || ""
227
+ sha = sha.slice(0..6)
227
228
 
228
- result = JSON.parse(response.body).first
229
- unless result
230
- puts ""
231
- print "Whoops - need to try again!".colorize(:red)
232
- puts ""
233
- print "We could not find any tags in the repo (".colorize(:light_red)
234
- print "#{repo}".colorize(:white)
235
- print ") on github.".colorize(:light_red)
236
- puts ""
237
- print "Raygun uses the 'largest' tag in a repository, where tags are sorted alphanumerically.".colorize(:light_red)
238
- puts ""
239
- print "E.g., tag 'v.0.10.0' > 'v.0.9.9' and 'x' > 'a'.".colorize(:light_red)
240
- print ""
241
- puts ""
242
- exit 1
229
+ rubocop_file = "https://raw.githubusercontent.com/#{C5_CONVENTIONS_REPO}/master/rubocop/rubocop.yml"
230
+ begin
231
+ rubocop_contents = URI.open(rubocop_file)
232
+ IO.write("#{@app_dir}/.rubocop.yml", <<~RUBOCOP_YML)
233
+ # Sourced from #{C5_CONVENTIONS_REPO} @ #{sha}
234
+ #
235
+ # If you make changes to this file, consider opening
236
+ # a PR to backport them to the c5-conventions repo:
237
+ # https://github.com/#{C5_CONVENTIONS_REPO}/blob/master/rubocop/rubocop.yml
238
+
239
+ #{rubocop_contents.string}
240
+ RUBOCOP_YML
241
+ rescue Errno::ENOENT, OpenURI::HTTPError => e
242
+ puts ""
243
+ puts "Failed to find the CarbonFive conventions rubocop file at #{rubocop_file}".colorize(:light_red)
244
+ puts "Error: #{e}".colorize(:light_red)
245
+ puts "You'll have to manage you're own `.rubocop.yml` setup".colorize(:light_red)
243
246
  end
244
-
245
- result
246
247
  end
247
248
 
248
249
  def camelize(string)
249
250
  result = string.sub(/^[a-z\d]*/) { $&.capitalize }
250
- result.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
251
+ result.gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
251
252
  end
252
253
 
253
254
  def titleize(underscored_string)
254
- result = underscored_string.gsub(/_/, ' ')
255
- result.gsub(/\b('?[a-z])/) { $1.capitalize }
255
+ result = underscored_string.tr("_", " ")
256
+ result.gsub(/\b('?[a-z])/) { Regexp.last_match(1).capitalize }
256
257
  end
257
258
 
258
259
  # Distinguish BSD vs GNU sed with the --version flag (only present in GNU sed).
259
260
  def sed_i
260
- @sed_format ||= begin
261
- %x{sed --version &> /dev/null}
262
- $?.success? ? "sed -i" : "sed -i ''"
263
- end
261
+ @sed_i ||= begin
262
+ `sed --version &> /dev/null`
263
+ $?.success? ? "sed -i" : "sed -i ''"
264
+ end
264
265
  end
265
266
 
266
267
  # Run a shell command and raise an exception if it fails.
267
268
  def shell(command)
268
- %x{#{command}}
269
+ output = `#{command}`
269
270
  raise "#{command} failed with status #{$?.exitstatus}." unless $?.success?
270
- end
271
271
 
272
- def self.parse(args)
273
- raygun = nil
274
-
275
- options = OpenStruct.new
276
- options.target_dir = nil
277
- options.prototype_repo = CARBONFIVE_REPO
278
-
279
- parser = OptionParser.new do |opts|
280
- opts.banner = "Usage: raygun [options] NEW_APP_DIRECTORY"
272
+ output
273
+ end
281
274
 
282
- opts.on('-h', '--help', "Show raygun usage") do
283
- usage_and_exit(opts)
284
- end
285
- opts.on('-p', '--prototype [github_repo]', "Prototype github repo (e.g. carbonfive/raygun-rails).") do |prototype|
286
- options.prototype_repo = prototype
275
+ class << self
276
+ # rubocop:disable Metrics/MethodLength
277
+ def parse(_args)
278
+ raygun = nil
279
+
280
+ options = OpenStruct.new
281
+ options.target_dir = nil
282
+ options.prototype_repo = CARBONFIVE_REPO
283
+
284
+ parser = OptionParser.new do |opts|
285
+ opts.banner = "Usage: raygun [options] NEW_APP_DIRECTORY"
286
+
287
+ opts.on("-h", "--help", "Show raygun usage") do
288
+ usage_and_exit(opts)
289
+ end
290
+ opts.on(
291
+ "-p",
292
+ "--prototype [github_repo]",
293
+ "Prototype github repo (e.g. carbonfive/raygun-rails)."
294
+ ) do |prototype|
295
+ options.prototype_repo = prototype
296
+ end
297
+
298
+ opts.on("-v", "--version", "Print the version number") do
299
+ puts Raygun::VERSION
300
+ exit 1
301
+ end
287
302
  end
288
- end
289
303
 
290
- begin
291
- parser.parse!
292
- options.target_dir = ARGV.first
304
+ begin
305
+ parser.parse!
306
+ options.target_dir = ARGV.first
293
307
 
294
- raise OptionParser::InvalidOption if options.target_dir.nil?
308
+ raise OptionParser::InvalidOption if options.target_dir.nil?
295
309
 
296
- raygun = Raygun::Runner.new(options.target_dir, options.prototype_repo)
310
+ raygun = Raygun::Runner.new(options.target_dir, options.prototype_repo)
311
+ rescue OptionParser::InvalidOption
312
+ usage_and_exit(parser)
313
+ end
297
314
 
298
- rescue OptionParser::InvalidOption
299
- usage_and_exit(parser)
315
+ raygun
300
316
  end
317
+ # rubocop:enable Metrics/MethodLength
301
318
 
302
- raygun
303
- end
304
-
305
- def self.usage_and_exit(parser)
306
- puts parser
307
- exit 1
319
+ def usage_and_exit(parser)
320
+ puts parser
321
+ exit 1
322
+ end
308
323
  end
309
324
  end
310
325
  end