-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.rb
95 lines (71 loc) · 2.01 KB
/
template.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# frozen_string_literal: true
# rubocop:disable Metrics/MethodLength
class << self
def execute
ask_for_versions
generate_clean_gemfile
generate_clean_database_yml
add_rubocop_files
add_rake_files
add_fixture_builder
add_license_finder_decisions
after_bundle do
generate_clean_rspec_files
fix_rubocop_issues
run_rake
singleton_class.remove_method(:source_paths)
end
end
def source_paths
[File.join(File.dirname(__FILE__), "templates")]
end
private
def ruby_version
@ruby_version ||= RUBY_VERSION
end
def rails_version
@rails_version ||= Rails.gem_version
end
def ask_for_versions
@ruby_version = ask("Ruby version? (default #{ruby_version})").presence
@rails_version = ask("Rails version? (default #{rails_version})").presence
end
def generate_clean_gemfile
remove_file("Gemfile", verbose: false)
template("Gemfile", ruby_version: ruby_version, rails_version: rails_version)
end
def generate_clean_database_yml
remove_file("config/database.yml", verbose: false)
template("config/database.yml")
end
def add_rubocop_files
copy_file(".rubocop.yml")
end
def add_rake_files
copy_file("lib/tasks/brakeman.rake")
copy_file("lib/tasks/rubocop.rake")
copy_file("lib/tasks/license_finder.rake")
copy_file("lib/tasks/default.rake")
end
def add_fixture_builder
copy_file("spec/support/fixture_builder.rb")
end
def add_license_finder_decisions
copy_file("doc/dependency_decisions.yml")
end
def generate_clean_rspec_files
generate("rspec:install")
remove_file("spec/spec_helper.rb", verbose: false)
copy_file("spec/spec_helper.rb")
remove_file("spec/rails_helper.rb", verbose: false)
copy_file("spec/rails_helper.rb")
end
def fix_rubocop_issues
run("bundle exec rubocop --auto-correct --out /dev/null")
end
def run_rake
rails_command("default", abort_on_failure: true, verbose: true)
end
end
# rubocop:enable Metrics/MethodLength
execute