raygun 0.0.17 → 0.0.18

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/CHANGES.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.0.18 [2013-01-24]
4
+
5
+ * Support generating an app in the current directory.
6
+ * Better handling of command line arguments.
7
+ * Include support for cane quality checks via ```rake spec:cane```.
8
+
3
9
  ## 0.0.17 [2013-01-17]
4
10
 
5
- * Configure .rbenv-version, .rvmrc, and Gemfile with the version of ruby used to execute raygun.
11
+ * Configure .ruby-version, .rvmrc, and Gemfile with the version of ruby used to execute raygun.
6
12
  * Improve the detfault email content.
7
13
  * Improve the raygun and app_prototype READMEs.
8
14
  * Use $PORT to set the server port for Heroku compatibility, with default set in .env.
@@ -34,6 +34,9 @@ group :test, :development do
34
34
  gem 'jasminerice'
35
35
  gem 'timecop'
36
36
  gem 'simplecov'
37
+ gem 'cane'
38
+ gem 'morecane'
39
+ gem 'quiet_assets'
37
40
  end
38
41
 
39
42
  group :development do
@@ -1,7 +1,7 @@
1
1
  class RegistrationsController < ApplicationController
2
2
 
3
3
  skip_authorization_check
4
-
4
+
5
5
  def new
6
6
  @user = User.new
7
7
  end
@@ -1,5 +1,5 @@
1
1
  class UserMailer < ActionMailer::Base
2
-
2
+
3
3
  default from: 'notifications@example.com'
4
4
 
5
5
  def activation_needed_email(user)
@@ -0,0 +1,30 @@
1
+ begin
2
+ require 'cane/rake_task'
3
+ require 'morecane'
4
+
5
+ desc "Run cane to check quality metrics"
6
+ Cane::RakeTask.new(:quality) do |cane|
7
+ cane.add_threshold 'coverage/covered_percent', :>=, 95
8
+
9
+ cane.no_style = false # Change to true to skip style checks
10
+ cane.style_measure = 120 # Maximum line length
11
+ cane.style_exclude = %w{
12
+ lib/templates/rspec/scaffold/controller_spec.rb
13
+ }
14
+
15
+ cane.no_doc = true # Change to false to enable documentation checks
16
+
17
+ cane.abc_max = 15 # Fail the build if complexity is too high.
18
+ # cane.abc_exclude = %w(
19
+ # User#bad_code_rising
20
+ # )
21
+
22
+ # Fail the build if the code includes debugging statements
23
+ cane.use Morecane::MustNotMatchCheck,
24
+ must_not_match_glob: "{app,lib,config,spec}/**/*.rb",
25
+ must_not_match_regexp: /binding\.pry|debugger/
26
+ end
27
+
28
+ rescue LoadError
29
+ warn "cane not available, quality task not provided."
30
+ end
@@ -16,12 +16,16 @@ begin
16
16
  end
17
17
  end
18
18
  end
19
+
20
+ desc 'Runs specs with coverage and cane checks'
21
+ task cane: ['spec:enable_coverage', 'spec:coverage', 'quality']
19
22
  end
20
23
 
21
24
  Rake::Task['spec'].enhance do
22
25
  Rake::Task['spec:javascripts'].invoke
23
26
  end
24
27
 
28
+
25
29
  rescue LoadError
26
30
  namespace :spec do
27
31
  task :javascripts do
data/bin/raygun CHANGED
@@ -1,65 +1,144 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'fileutils'
4
5
  require 'securerandom'
5
6
 
6
- def camelize(string)
7
- result = string.sub(/^[a-z\d]*/) { $&.capitalize }
8
- result.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
9
- end
7
+ module Raygun
8
+ class Runner
9
+ attr_accessor :app_name, :app_dir, :title_name, :snake_name, :camel_name, :dash_name
10
10
 
11
- def titleize(underscored_string)
12
- result = underscored_string.gsub(/_/, ' ')
13
- result.gsub(/\b('?[a-z])/) { $1.capitalize }
14
- end
11
+ def initialize(app_name_arg)
12
+ @app_dir = File.expand_path(app_name_arg.strip.to_s)
13
+ @app_name = File.basename(app_dir).gsub(/\s+/, '-')
14
+ @dash_name = app_name.gsub('_', '-')
15
+ @snake_name = app_name.gsub('-', '_')
16
+ @camel_name = camelize(snake_name)
17
+ @title_name = titleize(snake_name)
18
+ end
15
19
 
16
- unless ARGV[0]
17
- puts "Please specify where raygun should generate a project (e.g. projects/my_new_project)."
18
- puts "usage: raygun new_app_directory"
19
- exit 1
20
- end
20
+ def copy_prototype
21
+ FileUtils.mkdir_p(app_dir)
22
+
23
+ Dir.glob(File.expand_path('../../app_prototype/*', __FILE__), File::FNM_DOTMATCH) do |f|
24
+ next if %w{. ..}.include?(File.basename(f))
25
+ FileUtils.cp_r(f, app_dir)
26
+ end
27
+ end
28
+
29
+ def rename_new_app
30
+ Dir.chdir(app_dir) do
31
+ {
32
+ 'AppPrototype' => camel_name,
33
+ 'app-prototype' => dash_name,
34
+ 'app_prototype' => snake_name,
35
+ 'App Prototype' => title_name
36
+ }.each do |proto_name, new_name|
37
+ `find . -type f -print | xargs sed -i '' 's/#{proto_name}/#{new_name}/g'`
38
+ end
39
+ end
40
+ end
41
+
42
+ def configure_new_app
43
+ generate_tokens
44
+ update_ruby_version
45
+ end
46
+
47
+ def generate_tokens
48
+ Dir.chdir(app_dir) do
49
+ `sed -i '' 's/SUPER_SECRET_TOKEN_REPLACE_ME_TODO/#{SecureRandom.hex(128)}/' #{app_dir}/config/initializers/secret_token.rb`
50
+ end
51
+ end
52
+
53
+ def update_ruby_version
54
+ prototype_ruby_patch_level = File.read(File.expand_path('../../.rbenv-version', __FILE__)).strip
55
+ prototype_ruby_version = prototype_ruby_patch_level.match(/(\d\.\d\.\d).*/)[1]
56
+ current_ruby_version = RUBY_VERSION
57
+ current_ruby_patch_level = "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
58
+
59
+ Dir.chdir(app_dir) do
60
+ `sed -i '' 's/#{prototype_ruby_patch_level}/#{current_ruby_patch_level}/g' .rvmrc .ruby-version`
61
+ `sed -i '' 's/#{prototype_ruby_version}/#{current_ruby_version}/g' Gemfile`
62
+ end
63
+ end
64
+
65
+ def print_plan
66
+ puts
67
+ puts "Creating new app #{camel_name} in directory #{app_dir}..."
68
+ puts
69
+ end
70
+
71
+ def print_next_steps
72
+ puts "Done! Next steps..."
73
+ puts ""
74
+ puts "# Install updated dependencies"
75
+ puts "$ cd #{app_dir}"
76
+ puts "$ gem install bundler"
77
+ puts "$ bundle update"
78
+ puts ""
79
+ puts "# Prepare the database: schema and reference / sample data"
80
+ puts "$ rake db:setup db:sample_data"
81
+ puts ""
82
+ puts "# Run the specs (they should all pass)"
83
+ puts "$ rake"
84
+ puts ""
85
+ puts "# Load reference and sample data, then run the app and check things out"
86
+ puts "$ foreman start"
87
+ puts "$ open http://0.0.0.0:3000"
88
+ puts ""
89
+ puts "Enjoy your Carbon Five flavored Rails application!"
90
+ end
21
91
 
22
- app_dir = ARGV[0]
23
- app_name = File.basename(app_dir).gsub(/\s+/, '-')
24
- app_name_dash = app_name.gsub('_', '-')
25
- app_name_snake = app_name.gsub('-', '_')
26
- app_name_camel = camelize(app_name_snake)
27
- app_name_title = titleize(app_name_snake)
28
-
29
- ruby_version_patchlevel = `ruby -e 'print "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"'`
30
- ruby_version = `ruby -e 'print "#{RUBY_VERSION}"'`
31
-
32
- puts
33
- puts "Creating new app #{app_name_camel} in directory #{app_dir}..."
34
- puts
35
-
36
- FileUtils.cp_r(File.expand_path('../../app_prototype', __FILE__), app_dir)
37
-
38
- Dir.chdir(app_dir) do
39
- `find . -type f -print | xargs sed -i '' 's/AppPrototype/#{app_name_camel}/g'`
40
- `find . -type f -print | xargs sed -i '' 's/app-prototype/#{app_name_dash}/g'`
41
- `find . -type f -print | xargs sed -i '' 's/app_prototype/#{app_name_snake}/g'`
42
- `find . -type f -print | xargs sed -i '' 's/App Prototype/#{app_name_title}/g'`
43
- `sed -i '' 's/SUPER_SECRET_TOKEN_REPLACE_ME_TODO/#{SecureRandom.hex(128)}/' config/initializers/secret_token.rb`
44
- `sed -i '' 's/1.9.3-p327/#{ruby_version_patchlevel}/g' .rvmrc .ruby-version`
45
- `sed -i '' 's/1.9.3/#{ruby_version}/g' Gemfile`
46
-
47
- puts "Done! Next steps..."
48
- puts ""
49
- puts "# Install updated dependencies"
50
- puts "$ cd #{ARGV[0]}"
51
- puts "$ gem install bundler"
52
- puts "$ bundle update"
53
- puts ""
54
- puts "# Prepare the database: schema and reference / sample data"
55
- puts "$ rake db:setup db:sample_data"
56
- puts ""
57
- puts "# Run the specs (they should all pass)"
58
- puts "$ rake"
59
- puts ""
60
- puts "# Load reference and sample data, then run the app and check things out"
61
- puts "$ foreman start"
62
- puts "$ open http://0.0.0.0:3000"
63
- puts ""
64
- puts "Enjoy your Carbon Five flavored Rails application!"
92
+ protected
93
+
94
+ def camelize(string)
95
+ result = string.sub(/^[a-z\d]*/) { $&.capitalize }
96
+ result.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
97
+ end
98
+
99
+ def titleize(underscored_string)
100
+ result = underscored_string.gsub(/_/, ' ')
101
+ result.gsub(/\b('?[a-z])/) { $1.capitalize }
102
+ end
103
+
104
+ class << self
105
+ def parse(args)
106
+ raygun = nil
107
+
108
+ parser = OptionParser.new do |opts|
109
+ opts.banner = "Usage: raygun [options] NEW_APP_DIRECTORY"
110
+
111
+ opts.on("-h", "--help", "Show raygun usage") do |variable|
112
+ usage_and_exit(opts)
113
+ end
114
+
115
+ if ARGV.size == 0
116
+ usage_and_exit(opts)
117
+ else
118
+ raygun = Raygun::Runner.new(ARGV.first)
119
+ end
120
+ end
121
+
122
+ begin
123
+ parser.parse!
124
+ rescue OptionParser::InvalidOption
125
+ usage_and_exit(parser)
126
+ end
127
+
128
+ raygun
129
+ end
130
+
131
+ def usage_and_exit(parser)
132
+ puts parser
133
+ exit 1
134
+ end
135
+ end
136
+ end
65
137
  end
138
+
139
+ raygun = Raygun::Runner.parse(ARGV)
140
+ raygun.print_plan
141
+ raygun.copy_prototype
142
+ raygun.rename_new_app
143
+ raygun.configure_new_app
144
+ raygun.print_next_steps
@@ -1,3 +1,3 @@
1
1
  module Raygun
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.18"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: raygun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.18
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-01-17 00:00:00.000000000 Z
14
+ date: 2013-01-24 00:00:00.000000000 Z
15
15
  dependencies: []
16
16
  description: Carbon Five Rails application generator
17
17
  email:
@@ -109,6 +109,7 @@ files:
109
109
  - app_prototype/db/seeds.rb
110
110
  - app_prototype/lib/assets/.gitkeep
111
111
  - app_prototype/lib/tasks/.gitkeep
112
+ - app_prototype/lib/tasks/cane.rake
112
113
  - app_prototype/lib/tasks/coverage.rake
113
114
  - app_prototype/lib/tasks/db.rake
114
115
  - app_prototype/lib/tasks/spec.rake