raygun 1.0.4 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e084b27460032eefecb4daac7fda0290bdd7a81146031e6e449e64e6f21ff2c
4
- data.tar.gz: 3642729949a140b21817ee8a9f406458d83d00c4a3130da38c1503f0dd9e1c04
3
+ metadata.gz: c7ca3630bd95d0e0c12a7bf9d9f6b5cc0255ba5dfced51c83017a164f84ff147
4
+ data.tar.gz: 06ba32e033ec46d2ebe15f4e03c781b91ba94ac912075e9c1fff6872b68a5489
5
5
  SHA512:
6
- metadata.gz: cc05b65d10b93a5ee1e8d2883764e0cad8e26e0d4ee3ee5e55e1429d74cf4dcfacbde2c918c5827edfdf08203947aa8e62e4b1f3d1b33dc3fe8eb95e27bc6e0c
7
- data.tar.gz: 81fadf36b23b75a787ab94d8296189e539a186e9afd939d4610e98f292889a5ace35821b00581cd8b3e53ea866ecb35f7aa00e0c258709b491679ba2177cec2a
6
+ metadata.gz: 24416fbf00a23e6cb6b9afaf3c9ac3184bf1e99127c97a0f3db58d09364625e3f4ca5145e5801a039e4f878fa7b5e5952235866a792bfb462ec3b19c145a98ec
7
+ data.tar.gz: 496bcae1bc8c9bdaa1ed4975c9794c916a2187dfe76d1fb2df7fde190431f05c8a25cad2ed7b226898afc3d8a7249c02ee0ecdf6d2046e0633f806b74ba3e8b4
@@ -0,0 +1,99 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+ DisplayCopNames: true
4
+ DisplayStyleGuide: true
5
+
6
+ #
7
+ # Ruby Cops
8
+ #
9
+
10
+ Layout/CaseIndentation:
11
+ Enabled: false
12
+
13
+ Layout/FirstArrayElementIndentation:
14
+ EnforcedStyle: consistent
15
+
16
+ Layout/HashAlignment:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Max: 120
21
+
22
+ Layout/MultilineMethodCallIndentation:
23
+ EnforcedStyle: indented
24
+
25
+ Lint/AmbiguousBlockAssociation:
26
+ Enabled: false
27
+
28
+ Lint/ScriptPermission:
29
+ Exclude:
30
+ - "Rakefile"
31
+
32
+ Metrics/AbcSize:
33
+ Max: 35
34
+ Exclude:
35
+ - "spec/**/*"
36
+
37
+ Metrics/BlockLength:
38
+ CountComments: false
39
+ Max: 50
40
+ Exclude:
41
+ - "config/**/*"
42
+ - "spec/**/*"
43
+
44
+ Metrics/ClassLength:
45
+ Max: 250
46
+ Exclude:
47
+ - "spec/**/*"
48
+
49
+ Metrics/MethodLength:
50
+ Max: 25
51
+ Exclude:
52
+ - "db/migrate/*"
53
+ - "spec/**/*"
54
+
55
+ Naming/PredicateName:
56
+ Enabled: false
57
+
58
+ Security/YAMLLoad:
59
+ Enabled: false
60
+
61
+ Style/BarePercentLiterals:
62
+ EnforcedStyle: percent_q
63
+
64
+ Style/BlockDelimiters:
65
+ EnforcedStyle: braces_for_chaining
66
+
67
+ Style/Documentation:
68
+ Enabled: false
69
+
70
+ Style/EmptyMethod:
71
+ EnforcedStyle: expanded
72
+
73
+ Style/FrozenStringLiteralComment:
74
+ EnforcedStyle: never
75
+
76
+ Style/Lambda:
77
+ EnforcedStyle: literal
78
+
79
+ Style/ModuleFunction:
80
+ EnforcedStyle: extend_self
81
+
82
+ Style/MutableConstant:
83
+ Enabled: false
84
+
85
+ Style/PreferredHashMethods:
86
+ Enabled: false
87
+
88
+ Style/SpecialGlobalVars:
89
+ Enabled: false
90
+
91
+ Style/StringLiterals:
92
+ EnforcedStyle: double_quotes
93
+
94
+ Style/StringLiteralsInInterpolation:
95
+ EnforcedStyle: double_quotes
96
+
97
+ Style/StructInheritance:
98
+ Enabled: true
99
+
@@ -1 +1 @@
1
- 2.4.2
1
+ 2.6.5
data/CHANGES.md CHANGED
@@ -3,6 +3,26 @@
3
3
  **Note:** Don't let the apparent lack of activity here scare you away. Almost all changes are captured in the
4
4
  prototype repo (see [raygun-rails](https://github.com/carbonfive/raygun-rails)), and it's kept pretty well up to date.
5
5
 
6
+ ## 1.1.0 [2020-07-02]
7
+
8
+ Breaking:
9
+
10
+ * Require Ruby 2.4+ (#151)
11
+
12
+ New features:
13
+
14
+ * Copy `.rubocop.yml` template instead of using a fragile link to the c5-conventions repo (#148)
15
+ * Initialize zapped projects with a default branch of "main" (#157)
16
+
17
+ Docs:
18
+
19
+ * Add Bootstrap instructions to the README (it has been removed from the app prototype) (#141)
20
+
21
+ Housekeeping:
22
+
23
+ * Add bundler and rake development dependencies (#143)
24
+ * Upgrade to Ruby 2.6.5 (#142)
25
+
6
26
  ## 1.0.4 [2017-11-28]
7
27
 
8
28
  * Tweak instructions: use `heroku local` instead of `foreman s` (#138, thanks @mattbrictson)
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in raygun.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
- [![Gem Version](https://badge.fury.io/rb/raygun.png)](http://badge.fury.io/rb/raygun)
2
- <img src="https://raw.github.com/carbonfive/raygun/master/marvin.jpg" align="right"/>
1
+ [![Gem Version](https://badge.fury.io/rb/raygun.svg)](http://badge.fury.io/rb/raygun)
2
+ <img src="https://raw.github.com/carbonfive/raygun/main/marvin.jpg" align="right"/>
3
3
 
4
4
  # Raygun
5
5
 
@@ -18,7 +18,6 @@ Major tools/libraries:
18
18
  * PostgreSQL
19
19
  * Slim
20
20
  * Sass
21
- * Bootstrap
22
21
  * RSpec and Capybara
23
22
  * Factory Bot
24
23
  * SimpleCov
@@ -27,8 +26,7 @@ Major tools/libraries:
27
26
  the details).
28
27
 
29
28
  Raygun includes generator templates for controllers, views, and specs so that generated code follows best
30
- practices. For example, view generation produces bootstrap compatible markup and rspec specs use factory
31
- girl when appropriate.
29
+ practices. For example, rspec specs use factory bot when appropriate.
32
30
 
33
31
  Inspired by Xavier Shay work at Square and ThoughtBot's Suspenders. Thanks!
34
32
 
@@ -59,20 +57,54 @@ another ruby, just change the `Gemfile` and `.ruby-version` as necessary.
59
57
 
60
58
  ## Usage
61
59
 
62
- $ raygun your-project
60
+ ```bash
61
+ $ raygun your-project
62
+ ```
63
63
 
64
64
  Once your project is baked out, you can easily kick the wheels. Be sure that you have the prerequisites
65
65
  covered (see above).
66
66
 
67
- $ cd your-project
68
- $ bin/setup
67
+ ```bash
68
+ $ cd your-project
69
+ $ bin/setup
70
+
71
+ # Run the specs, they should all pass
72
+ $ bin/rake
73
+
74
+ # Fire up the app and open it in a browser
75
+ $ heroku local
76
+ $ open http://localhost:3000
77
+ ```
78
+
79
+ ## Next Steps
80
+
81
+ As you'll notice, the project comes with enough CSS (SCSS, actually) to establish some patterns. If you
82
+ need more of a framework, here are instructions on how to add Bootstrap to your new project.
83
+
84
+ ```bash
85
+ $ yarn add bootstrap
86
+ $ rails generate simple_form:install --bootstrap
87
+
88
+ # Answer Yes to the question about overwriting your existing `config/initializers/simple_form.rb`
89
+ ```
90
+
91
+ This generates an initializer and scaffold files for Rails view scaffolding.
92
+
93
+ Add Bootstrap imports to the top your `application.scss`
69
94
 
70
- # Run the specs, they should all pass
71
- $ bin/rake
95
+ ```css
96
+ // application.scss
97
+ @import "~bootstrap/scss/_functions";
98
+ @import "~bootstrap/scss/_variables";
99
+
100
+ ...
101
+ ```
102
+
103
+ Now you've got Bootstrap in the application.
104
+
105
+ We include `simple_form` in the project by default. For more information about using Bootstrap styling
106
+ on `simple_form` forms, check out the documentation here http://simple-form-bootstrap.plataformatec.com.br/documentation
72
107
 
73
- # Fire up the app and open it in a browser
74
- $ heroku local
75
- $ open http://localhost:3000
76
108
 
77
109
  ## Using a Custom Project Template
78
110
 
@@ -116,10 +148,18 @@ prototype (which is a valid rails app) and tag them when they should be used for
116
148
 
117
149
  ### Development
118
150
 
119
- Generate an example app using your local development version of Raygun:
151
+ To set up your local environment, run:
152
+
153
+ $ bin/setup
154
+
155
+ To run tests and rubocop checks:
156
+
157
+ $ bundle exec rake
158
+
159
+ To generate an example app using your local development version of Raygun:
120
160
 
121
- $ ./bin/raygun tmp/example_app
161
+ $ bin/raygun tmp/example_app
122
162
 
123
163
  ## Changes
124
164
 
125
- [View the Change Log](https://github.com/carbonfive/raygun/tree/master/CHANGES.md)
165
+ [View the Change Log](https://github.com/carbonfive/raygun/tree/main/CHANGES.md)
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require 'bundler/gem_tasks'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
+
5
+ RuboCop::RakeTask.new
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: %i[rubocop spec]
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,44 +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'
10
- require_relative 'template_repo'
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"
11
12
 
12
13
  module Raygun
13
14
  class Runner
14
- CARBONFIVE_REPO = 'carbonfive/raygun-rails'
15
+ CARBONFIVE_REPO = "carbonfive/raygun-rails"
16
+ C5_CONVENTIONS_REPO = "carbonfive/c5-conventions"
15
17
 
16
- 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,
17
20
  :current_ruby_version, :current_ruby_patch_level
18
21
 
19
22
  def initialize(target_dir, prototype_repo)
20
23
  @target_dir = target_dir
21
24
  @app_dir = File.expand_path(target_dir.strip.to_s)
22
- @app_name = File.basename(app_dir).gsub(/\s+/, '-')
23
- @dash_name = app_name.gsub('_', '-')
24
- @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("-", "_")
25
28
  @camel_name = camelize(snake_name)
26
29
  @title_name = titleize(snake_name)
27
30
  @prototype_repo = prototype_repo
28
31
 
29
32
  @current_ruby_version = RUBY_VERSION
30
- @current_ruby_patch_level = if RUBY_VERSION < '2.1.0' # Ruby adopted semver starting with 2.1.0.
31
- "#{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}"
32
35
  else
33
- "#{RUBY_VERSION}"
36
+ RUBY_VERSION.to_s
34
37
  end
35
38
  end
36
39
 
37
40
  def check_target
38
- unless Dir["#{@app_dir}/*"].empty?
39
- puts "Misfire! The target directory isn't empty... aim elsewhere."
40
- exit 1
41
- 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
42
45
  end
43
46
 
44
47
  def fetch_prototype
@@ -55,17 +58,17 @@ module Raygun
55
58
  $stdout.flush
56
59
 
57
60
  cached_prototypes_dir = File.join(Dir.home, ".raygun")
58
- @prototype = "#{cached_prototypes_dir}/#{name.gsub('/','--')}-#{sha}.tar.gz"
61
+ @prototype = "#{cached_prototypes_dir}/#{name.gsub("/", "--")}-#{sha}.tar.gz"
59
62
 
60
63
  # Do we already have the tarball cached under ~/.raygun?
61
- if File.exists?(@prototype)
64
+ if File.exist?(@prototype)
62
65
  puts " Using cached version.".colorize(:yellow)
63
66
  else
64
67
  print " Downloading...".colorize(:yellow)
65
68
  $stdout.flush
66
69
 
67
70
  # Download the tarball and install in the cache.
68
- Dir.mkdir(cached_prototypes_dir, 0755) unless Dir.exists?(cached_prototypes_dir)
71
+ Dir.mkdir(cached_prototypes_dir, 0o755) unless Dir.exist?(cached_prototypes_dir)
69
72
  shell "curl -s -L #{tarball_url} -o #{@prototype}"
70
73
  puts " done!".colorize(:yellow)
71
74
  end
@@ -73,24 +76,23 @@ module Raygun
73
76
 
74
77
  def check_raygun_version
75
78
  required_raygun_version =
76
- %x{tar xfz #{@prototype} --include "*.raygun-version" -O 2> /dev/null}.chomp ||
77
- ::Raygun::VERSION
78
-
79
- if Gem::Version.new(required_raygun_version) > Gem::Version.new(::Raygun::VERSION)
80
- puts ""
81
- print "Hold up!".colorize(:red)
82
- print " This version of the raygun gem (".colorize(:light_red)
83
- print "#{::Raygun::VERSION})".colorize(:white)
84
- print " is too old to generate this application (needs ".colorize(:light_red)
85
- print "#{required_raygun_version}".colorize(:white)
86
- puts " or newer).".colorize(:light_red)
87
- puts ""
88
- print "Please update the gem by running ".colorize(:light_red)
89
- print "gem update raygun".colorize(:white)
90
- puts ", and try again. Thanks!".colorize(:light_red)
91
- puts ""
92
- exit 1
93
- 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
94
96
  end
95
97
 
96
98
  def copy_prototype
@@ -101,25 +103,28 @@ module Raygun
101
103
  # Github includes an extra directory layer in the tag tarball.
102
104
  extraneous_dir = Dir.glob("#{app_dir}/*").first
103
105
  dirs_to_move = Dir.glob("#{extraneous_dir}/*", File::FNM_DOTMATCH)
104
- .reject { |d| %w{. ..}.include?(File.basename(d)) }
106
+ .reject { |d| %w[. ..].include?(File.basename(d)) }
105
107
 
106
108
  FileUtils.mv dirs_to_move, app_dir
107
109
  FileUtils.remove_dir extraneous_dir
110
+
111
+ fetch_rubocop_file if @prototype_repo == CARBONFIVE_REPO
108
112
  end
109
113
 
110
114
  def rename_new_app
111
115
  Dir.chdir(app_dir) do
112
116
  {
113
- 'AppPrototype' => camel_name,
114
- 'app-prototype' => dash_name,
115
- 'app_prototype' => snake_name,
116
- 'App Prototype' => title_name
117
+ "AppPrototype" => camel_name,
118
+ "app-prototype" => dash_name,
119
+ "app_prototype" => snake_name,
120
+ "App Prototype" => title_name
117
121
  }.each do |proto_name, new_name|
118
122
  shell "find . -type f -print | xargs #{sed_i} 's/#{proto_name}/#{new_name}/g'"
119
123
  end
120
124
 
121
- %w(d f).each do |find_type|
122
- shell "find . -depth -type #{find_type} -name '*app_prototype*' -exec bash -c 'mv $0 ${0/app_prototype/#{snake_name}}' {} \\;"
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}}' {} \\;"
123
128
  end
124
129
  end
125
130
  end
@@ -149,26 +154,33 @@ module Raygun
149
154
  def initialize_git
150
155
  Dir.chdir(app_dir) do
151
156
  shell "git init"
157
+ shell "git checkout -q -b main"
152
158
  shell "git add -A ."
153
159
  shell "git commit -m 'Raygun-zapped skeleton.'"
154
160
  end
155
161
  end
156
162
 
163
+ # rubocop:disable Metrics/AbcSize
157
164
  def print_plan
158
- puts ' ____ '.colorize(:light_yellow)
165
+ puts " ____ ".colorize(:light_yellow)
159
166
  puts ' / __ \____ ___ ______ ___ ______ '.colorize(:light_yellow)
160
167
  puts ' / /_/ / __ `/ / / / __ `/ / / / __ \ '.colorize(:light_yellow)
161
- puts ' / _, _/ /_/ / /_/ / /_/ / /_/ / / / / '.colorize(:light_yellow)
168
+ puts " / _, _/ /_/ / /_/ / /_/ / /_/ / / / / ".colorize(:light_yellow)
162
169
  puts ' /_/ |_|\__,_/\__, /\__, /\__,_/_/ /_/ '.colorize(:light_yellow)
163
- puts ' /____//____/ '.colorize(:light_yellow)
170
+ puts " /____//____/ ".colorize(:light_yellow)
164
171
  puts
165
- 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)
166
174
  puts
167
- puts "-".colorize(:blue) + " Application Name:".colorize(:light_blue) + " #{title_name}".colorize(:light_reen)
168
- puts "-".colorize(:blue) + " Project Template:".colorize(:light_blue) + " #{prototype_repo}".colorize(:light_reen)
169
- 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)
170
181
  puts
171
182
  end
183
+ # rubocop:enable Metrics/AbcSize
172
184
 
173
185
  def print_next_steps
174
186
  if @prototype_repo == CARBONFIVE_REPO
@@ -178,6 +190,7 @@ module Raygun
178
190
  end
179
191
  end
180
192
 
193
+ # rubocop:disable Metrics/AbcSize
181
194
  def print_next_steps_carbon_five
182
195
  puts ""
183
196
  puts "Zap! Your application is ready. Next steps...".colorize(:yellow)
@@ -193,8 +206,12 @@ module Raygun
193
206
  puts "$".colorize(:blue) + " heroku local".colorize(:light_blue)
194
207
  puts "$".colorize(:blue) + " open http://localhost:3000".colorize(:light_blue)
195
208
  puts ""
209
+ puts "# For some suggested next steps, 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 ""
196
212
  puts "Enjoy your Carbon Five flavored Rails application!".colorize(:yellow)
197
213
  end
214
+ # rubocop:enable Metrics/AbcSize
198
215
 
199
216
  def print_next_steps_for_custom_repo
200
217
  puts ""
@@ -205,66 +222,104 @@ module Raygun
205
222
 
206
223
  protected
207
224
 
225
+ def fetch_rubocop_file
226
+ sha = shell("git ls-remote https://github.com/#{C5_CONVENTIONS_REPO} master") || ""
227
+ sha = sha.slice(0..6)
228
+
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)
246
+ end
247
+ end
248
+
208
249
  def camelize(string)
209
250
  result = string.sub(/^[a-z\d]*/) { $&.capitalize }
210
- result.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
251
+ result.gsub(%r{(?:_|(/))([a-z\d]*)}) { "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" }
211
252
  end
212
253
 
213
254
  def titleize(underscored_string)
214
- result = underscored_string.gsub(/_/, ' ')
215
- result.gsub(/\b('?[a-z])/) { $1.capitalize }
255
+ result = underscored_string.tr("_", " ")
256
+ result.gsub(/\b('?[a-z])/) { Regexp.last_match(1).capitalize }
216
257
  end
217
258
 
218
259
  # Distinguish BSD vs GNU sed with the --version flag (only present in GNU sed).
219
260
  def sed_i
220
- @sed_format ||= begin
221
- %x{sed --version &> /dev/null}
222
- $?.success? ? "sed -i" : "sed -i ''"
223
- end
261
+ @sed_i ||= begin
262
+ `sed --version &> /dev/null`
263
+ $?.success? ? "sed -i" : "sed -i ''"
264
+ end
224
265
  end
225
266
 
226
267
  # Run a shell command and raise an exception if it fails.
227
268
  def shell(command)
228
- %x{#{command}}
269
+ output = `#{command}`
229
270
  raise "#{command} failed with status #{$?.exitstatus}." unless $?.success?
230
- end
231
-
232
- def self.parse(args)
233
- raygun = nil
234
-
235
- options = OpenStruct.new
236
- options.target_dir = nil
237
- options.prototype_repo = CARBONFIVE_REPO
238
271
 
239
- parser = OptionParser.new do |opts|
240
- opts.banner = "Usage: raygun [options] NEW_APP_DIRECTORY"
272
+ output
273
+ end
241
274
 
242
- opts.on('-h', '--help', "Show raygun usage") do
243
- usage_and_exit(opts)
244
- end
245
- opts.on('-p', '--prototype [github_repo]', "Prototype github repo (e.g. carbonfive/raygun-rails).") do |prototype|
246
- 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
247
302
  end
248
- end
249
303
 
250
- begin
251
- parser.parse!
252
- options.target_dir = ARGV.first
304
+ begin
305
+ parser.parse!
306
+ options.target_dir = ARGV.first
253
307
 
254
- raise OptionParser::InvalidOption if options.target_dir.nil?
308
+ raise OptionParser::InvalidOption if options.target_dir.nil?
255
309
 
256
- 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
257
314
 
258
- rescue OptionParser::InvalidOption
259
- usage_and_exit(parser)
315
+ raygun
260
316
  end
317
+ # rubocop:enable Metrics/MethodLength
261
318
 
262
- raygun
263
- end
264
-
265
- def self.usage_and_exit(parser)
266
- puts parser
267
- exit 1
319
+ def usage_and_exit(parser)
320
+ puts parser
321
+ exit 1
322
+ end
268
323
  end
269
324
  end
270
325
  end
@@ -3,7 +3,7 @@ module Raygun
3
3
  attr_reader :name, :branch, :tarball, :sha
4
4
 
5
5
  def initialize(repo)
6
- @name, @branch = repo.split('#').map(&:strip)
6
+ @name, @branch = repo.split("#").map(&:strip)
7
7
  fetch
8
8
  end
9
9
 
@@ -11,6 +11,7 @@ module Raygun
11
11
 
12
12
  def fetch
13
13
  return if @branch && @sha
14
+
14
15
  @branch ? fetch_branches : fetch_tags
15
16
  end
16
17
 
@@ -19,12 +20,12 @@ module Raygun
19
20
  print "Whoops - need to try again!".colorize(:red)
20
21
  puts ""
21
22
  print "We could not find (".colorize(:light_red)
22
- print "#{name}".colorize(:white)
23
+ print name.to_s.colorize(:white)
23
24
  print "##{branch}".colorize(:white) if @branch
24
25
  print ") on github.".colorize(:light_red)
25
26
  puts ""
26
27
  print "The response from github was a (".colorize(:light_red)
27
- print "#{response.code}".colorize(:white)
28
+ print response.code.to_s.colorize(:white)
28
29
  puts ") which I'm sure you can fix right up!".colorize(:light_red)
29
30
  puts ""
30
31
  exit 1
@@ -35,10 +36,11 @@ module Raygun
35
36
  print "Whoops - need to try again!".colorize(:red)
36
37
  puts ""
37
38
  print "We could not find any tags in the repo (".colorize(:light_red)
38
- print "#{name}".colorize(:white)
39
+ print name.to_s.colorize(:white)
39
40
  print ") on github.".colorize(:light_red)
40
41
  puts ""
41
- print "Raygun uses the 'largest' tag in a repository, where tags are sorted alphanumerically.".colorize(:light_red)
42
+ print "Raygun uses the 'largest' tag in a repository, " \
43
+ "where tags are sorted alphanumerically.".colorize(:light_red)
42
44
  puts ""
43
45
  print "E.g., tag 'v.0.10.0' > 'v.0.9.9' and 'x' > 'a'.".colorize(:light_red)
44
46
  print ""
@@ -50,8 +52,8 @@ module Raygun
50
52
  response = http_get("https://api.github.com/repos/#{name}/branches/#{branch}")
51
53
  handle_github_error(response) unless response.code == "200"
52
54
  result = JSON.parse(response.body)
53
- @sha = result['commit']['sha']
54
- @tarball = result['_links']['html'].gsub(%r(/tree/#{branch}), "/archive/#{branch}.tar.gz")
55
+ @sha = result["commit"]["sha"]
56
+ @tarball = result["_links"]["html"].gsub(%r{/tree/#{branch}}, "/archive/#{branch}.tar.gz")
55
57
  end
56
58
 
57
59
  def fetch_tags
@@ -60,17 +62,17 @@ module Raygun
60
62
 
61
63
  result = JSON.parse(response.body).first
62
64
  handle_missing_tag_error unless result
63
- @sha = result['commit']['sha']
64
- @tarball = result['tarball_url']
65
+ @sha = result["commit"]["sha"]
66
+ @tarball = result["tarball_url"]
65
67
  end
66
68
 
67
69
  def http_get(url)
68
- uri = URI.parse(url)
70
+ uri = URI(url)
69
71
  http = Net::HTTP.new(uri.host, uri.port)
70
72
  http.use_ssl = true
71
- request = Net::HTTP::Get.new(URI.encode(url))
73
+ request = Net::HTTP::Get.new(uri)
72
74
 
73
- response = http.request(request)
75
+ http.request(request)
74
76
  end
75
77
  end
76
78
  end
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,23 +1,28 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- File.expand_path('../lib', __FILE__).tap do |lib|
1
+ File.expand_path("lib", __dir__).tap do |lib|
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
  end
6
4
 
7
- require 'raygun/version'
5
+ require "raygun/version"
8
6
 
9
7
  Gem::Specification.new do |gem|
10
8
  gem.name = "raygun"
11
9
  gem.version = Raygun::VERSION
12
10
  gem.authors = ["Christian Nelson", "Jonah Williams", "Jason Wadsworth"]
13
11
  gem.email = ["christian@carbonfive.com"]
14
- gem.description = %q{Carbon Five Rails application generator}
15
- gem.summary = %q{Generates and customizes Rails applications with Carbon Five best practices baked in.}
12
+ gem.description = "Carbon Five Rails application generator"
13
+ gem.summary = "Generates and customizes Rails applications with Carbon Five best practices baked in."
16
14
  gem.homepage = "https://github.com/carbonfive/raygun"
17
- gem.license = 'MIT'
15
+ gem.license = "MIT"
18
16
 
19
- gem.files = `git ls-files`.split($/)
17
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
20
18
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
21
19
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
20
  gem.require_paths = ["lib"]
21
+
22
+ gem.required_ruby_version = "~> 2.4"
23
+
24
+ gem.add_development_dependency "bundler", "~> 2.0"
25
+ gem.add_development_dependency "rake", "~> 13.0"
26
+ gem.add_development_dependency "rspec", "~> 3.9"
27
+ gem.add_development_dependency "rubocop", "0.79.0"
23
28
  end
@@ -0,0 +1,3 @@
1
+ require_relative "../spec_helper"
2
+
3
+ describe Raygun::Runner
@@ -0,0 +1,27 @@
1
+ require_relative "../spec_helper"
2
+ require_relative "../../lib/raygun/raygun"
3
+
4
+ describe Raygun::Runner do
5
+ describe "#fetch_rubocop_file" do
6
+ context "the repo is the standard carbonfive raygun-rails repo" do
7
+ before do
8
+ @runner = described_class.new("target/dir", "carbonfive/raygun-rails")
9
+ allow(URI).to receive(:open).and_return(StringIO.new("# rubocop contents"))
10
+ allow(IO).to receive(:write)
11
+ allow(@runner).to receive(:shell).and_return("GitSHAgoeshere")
12
+ end
13
+ it "inserts a copy of the rubocop file pulled from the carbonfive/c5-conventions repo" do
14
+ @runner.send(:fetch_rubocop_file)
15
+ expect(@runner).to have_received(:shell)
16
+ .with("git ls-remote https://github.com/carbonfive/c5-conventions master")
17
+ expect(URI).to have_received(:open)
18
+ .with("https://raw.githubusercontent.com/carbonfive/c5-conventions/master/rubocop/rubocop.yml")
19
+ expect(IO).to have_received(:write) do |path, contents|
20
+ expect(path).to eq(File.absolute_path("target/dir/.rubocop.yml"))
21
+ expect(contents).to include("@ GitSHA")
22
+ expect(contents).to include("# rubocop contents")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1 @@
1
+ require "rspec"
metadata CHANGED
@@ -1,26 +1,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Nelson
8
8
  - Jonah Williams
9
9
  - Jason Wadsworth
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-11-28 00:00:00.000000000 Z
14
- dependencies: []
13
+ date: 2020-07-02 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bundler
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '2.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '13.0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '13.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.9'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '3.9'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rubocop
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '='
62
+ - !ruby/object:Gem::Version
63
+ version: 0.79.0
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '='
69
+ - !ruby/object:Gem::Version
70
+ version: 0.79.0
15
71
  description: Carbon Five Rails application generator
16
72
  email:
17
73
  - christian@carbonfive.com
18
74
  executables:
19
75
  - raygun
76
+ - setup
20
77
  extensions: []
21
78
  extra_rdoc_files: []
22
79
  files:
23
80
  - ".gitignore"
81
+ - ".rubocop.yml"
24
82
  - ".ruby-gemset"
25
83
  - ".ruby-version"
26
84
  - CHANGES.md
@@ -29,35 +87,41 @@ files:
29
87
  - README.md
30
88
  - Rakefile
31
89
  - bin/raygun
90
+ - bin/setup
32
91
  - lib/colorize.rb
33
92
  - lib/raygun/raygun.rb
34
93
  - lib/raygun/template_repo.rb
35
94
  - lib/raygun/version.rb
36
95
  - marvin.jpg
37
96
  - raygun.gemspec
97
+ - spec/raygun/raygun.rb
98
+ - spec/raygun/runner_spec.rb
99
+ - spec/spec_helper.rb
38
100
  homepage: https://github.com/carbonfive/raygun
39
101
  licenses:
40
102
  - MIT
41
103
  metadata: {}
42
- post_install_message:
104
+ post_install_message:
43
105
  rdoc_options: []
44
106
  require_paths:
45
107
  - lib
46
108
  required_ruby_version: !ruby/object:Gem::Requirement
47
109
  requirements:
48
- - - ">="
110
+ - - "~>"
49
111
  - !ruby/object:Gem::Version
50
- version: '0'
112
+ version: '2.4'
51
113
  required_rubygems_version: !ruby/object:Gem::Requirement
52
114
  requirements:
53
115
  - - ">="
54
116
  - !ruby/object:Gem::Version
55
117
  version: '0'
56
118
  requirements: []
57
- rubyforge_project:
58
- rubygems_version: 2.7.1
59
- signing_key:
119
+ rubygems_version: 3.0.3
120
+ signing_key:
60
121
  specification_version: 4
61
122
  summary: Generates and customizes Rails applications with Carbon Five best practices
62
123
  baked in.
63
- test_files: []
124
+ test_files:
125
+ - spec/raygun/raygun.rb
126
+ - spec/raygun/runner_spec.rb
127
+ - spec/spec_helper.rb