rails-new-app 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests.yml +28 -0
  3. data/.gitignore +2 -0
  4. data/Gemfile +14 -0
  5. data/Gemfile.lock +60 -0
  6. data/README.md +60 -20
  7. data/Rakefile +9 -0
  8. data/lib/rails-new-app.rb +1 -1
  9. data/lib/rails-new-app/processors/authentication_processor.rb +16 -0
  10. data/lib/rails-new-app/processors/authorization_processor.rb +18 -0
  11. data/lib/rails-new-app/runner.rb +97 -146
  12. data/lib/rails-new-app/screens.rb +8 -0
  13. data/lib/rails-new-app/screens/app_name_screen.rb +28 -0
  14. data/lib/rails-new-app/screens/auth_screen.rb +26 -0
  15. data/lib/rails-new-app/screens/authentication_screen.rb +27 -0
  16. data/lib/rails-new-app/screens/authorization_screen.rb +27 -0
  17. data/lib/rails-new-app/screens/choice_screen.rb +52 -0
  18. data/lib/rails-new-app/{steps/code_coverage_step.rb → screens/code_coverage_screen.rb} +3 -3
  19. data/lib/rails-new-app/{steps/database_step.rb → screens/database_screen.rb} +7 -5
  20. data/lib/rails-new-app/{steps/form_builder_step.rb → screens/form_builder_screen.rb} +2 -2
  21. data/lib/rails-new-app/{steps/java_script_framework_step.rb → screens/java_script_framework_screen.rb} +2 -2
  22. data/lib/rails-new-app/screens/menu_screen.rb +61 -0
  23. data/lib/rails-new-app/{steps/pagination_step.rb → screens/pagination_screen.rb} +2 -2
  24. data/lib/rails-new-app/screens/review_and_confirm_screen.rb +59 -0
  25. data/lib/rails-new-app/{steps/ruby_linter_step.rb → screens/ruby_linter_screen.rb} +2 -2
  26. data/lib/rails-new-app/screens/screen.rb +66 -0
  27. data/lib/rails-new-app/{steps/template_engine_step.rb → screens/template_engine_screen.rb} +2 -2
  28. data/lib/rails-new-app/{steps/test_factory_step.rb → screens/test_factory_screen.rb} +3 -3
  29. data/lib/rails-new-app/{steps/test_fake_data.rb → screens/test_fake_data_screen.rb} +3 -3
  30. data/lib/rails-new-app/{steps/test_runner_step.rb → screens/test_runner_screen.rb} +3 -3
  31. data/lib/rails-new-app/{steps/yes_no_choice_step.rb → screens/yes_no_choice_screen.rb} +1 -1
  32. data/lib/rails-new-app/templates/cancancan-config.rb +1 -0
  33. data/lib/rails-new-app/templates/cancancan-gemfile.rb +1 -0
  34. data/lib/rails-new-app/templates/devise-config.rb +1 -0
  35. data/lib/rails-new-app/templates/devise-gemfile.rb +1 -0
  36. data/lib/rails-new-app/templates/pagy-config.rb +1 -1
  37. data/lib/rails-new-app/templates/pundit-config.rb +7 -0
  38. data/lib/rails-new-app/templates/pundit-gemfile.rb +1 -0
  39. data/lib/rails-new-app/version.rb +1 -1
  40. metadata +34 -18
  41. data/lib/rails-new-app/steps.rb +0 -7
  42. data/lib/rails-new-app/steps/app_name_step.rb +0 -20
  43. data/lib/rails-new-app/steps/choice_step.rb +0 -45
  44. data/lib/rails-new-app/steps/rails_version_step.rb +0 -34
  45. data/lib/rails-new-app/steps/step.rb +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93081e6a5b8f36849c4d4a799966cefd00ca97133cfe35bef967c020fd7eff63
4
- data.tar.gz: b629ee3815475d9917eeefedc90d8973a9d7162c5b27ab93c13625646c038df3
3
+ metadata.gz: a2d108c27dd154b223f683f5cd2fdd6efc5871a5419146de56112fff357de6d3
4
+ data.tar.gz: d4cfbbb2754df7c54d711e71679c1763e01659594db614f67647150a3bca3f51
5
5
  SHA512:
6
- metadata.gz: 5a2d9590d597b7ac2abe68b4d27ac09b274ee48fc52dc9bba40cfa28c3c41357bb5594e0be4fef2859df877936b20a98ecb5c1d4bb20366dc8c9d5cf69cd318f
7
- data.tar.gz: 56bc800f44e839ae8ba63fb810890365d7963e8100c6e01fafa494a8846cc0d43039fc279bdb22820e2b6ab78e880a27f187882e14580650c4137018f8c026cf
6
+ metadata.gz: 206bd5da44b2aaca70734ebf6db67900e214774bc3775638af3589c2abf1b085e08fe8b3cf01ee5ae165c4c448c9dd4f616851e86ff03a1401f0b6e5ed415e89
7
+ data.tar.gz: fd63025c4f3a0ef5f27e1d7a16443c669b67122f22b2132ef7dd8905b628e782664c1cfc8c0f802f103dc07dc84fc5664ff96622a813dd7ff969e0c876374e84
@@ -0,0 +1,28 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ['2.6', '2.7', '3.0']
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
21
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
22
+ # uses: ruby/setup-ruby@v1
23
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
24
+ with:
25
+ ruby-version: ${{ matrix.ruby-version }}
26
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
27
+ - name: Run tests
28
+ run: COVERAGE=true bundle exec rake test
data/.gitignore CHANGED
@@ -54,3 +54,5 @@ build-iPhoneSimulator/
54
54
 
55
55
  # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
56
  # .rubocop-https?--*
57
+
58
+ defaults.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "minitest"
4
+ gem "rake"
5
+ gem "byebug"
6
+
7
+ group :development, :test do
8
+ gem "standard"
9
+ end
10
+
11
+ group :test do
12
+ gem "simplecov", require: false
13
+ gem "simplecov-console", require: false
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ ansi (1.5.0)
5
+ ast (2.4.2)
6
+ byebug (11.1.3)
7
+ docile (1.4.0)
8
+ minitest (5.14.4)
9
+ parallel (1.20.1)
10
+ parser (3.0.1.1)
11
+ ast (~> 2.4.1)
12
+ rainbow (3.0.0)
13
+ rake (13.0.3)
14
+ regexp_parser (2.1.1)
15
+ rexml (3.2.5)
16
+ rubocop (1.14.0)
17
+ parallel (~> 1.10)
18
+ parser (>= 3.0.0.0)
19
+ rainbow (>= 2.2.2, < 4.0)
20
+ regexp_parser (>= 1.8, < 3.0)
21
+ rexml
22
+ rubocop-ast (>= 1.5.0, < 2.0)
23
+ ruby-progressbar (~> 1.7)
24
+ unicode-display_width (>= 1.4.0, < 3.0)
25
+ rubocop-ast (1.7.0)
26
+ parser (>= 3.0.1.1)
27
+ rubocop-performance (1.11.2)
28
+ rubocop (>= 1.7.0, < 2.0)
29
+ rubocop-ast (>= 0.4.0)
30
+ ruby-progressbar (1.11.0)
31
+ simplecov (0.21.2)
32
+ docile (~> 1.1)
33
+ simplecov-html (~> 0.11)
34
+ simplecov_json_formatter (~> 0.1)
35
+ simplecov-console (0.9.1)
36
+ ansi
37
+ simplecov
38
+ terminal-table
39
+ simplecov-html (0.12.3)
40
+ simplecov_json_formatter (0.1.3)
41
+ standard (1.1.1)
42
+ rubocop (= 1.14.0)
43
+ rubocop-performance (= 1.11.2)
44
+ terminal-table (3.0.1)
45
+ unicode-display_width (>= 1.1.1, < 3)
46
+ unicode-display_width (2.0.0)
47
+
48
+ PLATFORMS
49
+ x86_64-linux
50
+
51
+ DEPENDENCIES
52
+ byebug
53
+ minitest
54
+ rake
55
+ simplecov
56
+ simplecov-console
57
+ standard
58
+
59
+ BUNDLED WITH
60
+ 2.2.11
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # rails-new-app
2
- Command-line tool to assist in the creation of new Rails 5 and 6 apps
2
+ Command-line tool to assist in the creation of new Rails 6 apps
3
3
 
4
4
  ## Installation:
5
5
 
@@ -9,23 +9,22 @@ Run `gem install "rails-new-app"`
9
9
 
10
10
  Run `rails-new-app` command and follow the step by step wizard.
11
11
 
12
- ### Alternative
13
-
14
- If, for any reason, the menu navigation does not work, run `rails-new-app navigation=false`.
12
+ It will use the current default Rails version, so you should install the version you want to use, these generators are currently tested with Rails 6.
15
13
 
16
14
  ## Current configurations:
17
- - Rails version (validate and install)
18
- - Database: none / MySQL / PostgreSQL / SQLite
15
+ - Database: MySQL / PostgreSQL / SQLite
19
16
  - Tests:
20
17
  - - runner: none / Minitest / RSpec
21
18
  - - CodeCoverage: none / Simplecov
22
19
  - - Factories: none / FactoryBot
23
20
  - - Fake data: none / Faker
24
21
  - TemplateEngine: None (just ERB) / Slim / HAML
25
- - RubyLinter: None / RuboCop / StandardRB
26
22
  - FormBuilder: None / Simple Form / Formtastic
27
- - JS Framework: None / ReactJS / VueJS / Angular / Elm / Stimulus
28
23
  - Pagination: None / Pagy / Kaminari / WillPaginate
24
+ - JS Framework: None / ReactJS / VueJS / Angular / Elm / Stimulus
25
+ - Authorization: None / Pundit / CanCanCan
26
+ - Authentication: None / Devise
27
+ - RubyLinter: None / RuboCop / StandardRB
29
28
 
30
29
  ## TODOs and ideas:
31
30
  - improve GUI and UX
@@ -36,29 +35,33 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
36
35
  - add more tools
37
36
  - support `rails new` flags configuration
38
37
  - research requirements
39
- - improve validations (check rails version, ruby version, if gems are compatible with rails, etc)
40
- - show the user the current Ruby version
41
38
  - support a `rails-new-app-defaults` file at the HOME dir to set default options if empty answers
42
39
 
43
40
  #### Ideas for other tools:
44
- - support other databases like MongoDB that require more config
45
- - type of app: standard/minimal/api
41
+ - dotenv/figaro
42
+ - resque/sideqik/suckerpunch/other?
43
+ - CSS framework? bootstrap/tailwind/material/spectre/bulma (this affects the form builders processor)
46
44
  - CI config? github actions / travis / circleci / bitbucket / gitlab / others
47
- - js linter? None/ESlint/StandardJS
48
- - devise?
49
45
  - carrierwave/paperclip/dragonfly?
46
+ - js linter? None/ESlint/StandardJS
50
47
  - exception_notification / airbreak / other reporting tools
51
- - dotenv/figaro
52
48
  - redis?
53
49
  - memcached/dalli/other?
54
- - resque/sideqik/suckerpunch/other?
55
- - CSS framework? bootstrap/tailwind/material/spectre/bulma (this affects the form builders processor)
56
50
  - add basic docker config?
57
- - admin gems? ActiveAdmin/RailsAdmin/Trestle/others
58
51
  - pre-commit hooks? overcommit
59
- - cancancan/pundit ?
52
+ - admin gems? ActiveAdmin/RailsAdmin/Trestle/others
53
+ - type of app: standard/minimal/api
54
+ - support other databases like MongoDB that require more config
55
+
56
+ ## For developers
60
57
 
61
- ## Adding more configurations and tools:
58
+ ### Setup:
59
+
60
+ - Clone the repo
61
+ - Run `bundle install`
62
+ - You can run the app with `./exe/rails-new-app`
63
+
64
+ ### Adding more configurations and tools:
62
65
 
63
66
  1. Add a new step at `lib/rails-new-app/steps` (or modify an existing one)
64
67
  2. Collect step config in the `config` hash
@@ -70,6 +73,36 @@ If, for any reason, the menu navigation does not work, run `rails-new-app naviga
70
73
 
71
74
  * Steps 5 and 6 are split so we can run `bundle install` once.
72
75
 
76
+ ### Quick scripted execution:
77
+
78
+ Since the app uses the STDIN to configure the generator, you can pipe a stream of inputs that a user would do to the command to quickly set all the desired options. For example:
79
+
80
+ ```
81
+ # inside any text file, like... defaults.txt
82
+ 1
83
+ MyApp
84
+ 2
85
+ 3
86
+ 8
87
+ 2
88
+ 0
89
+ Y
90
+ ```
91
+
92
+ These inputs set the name (1) to `MyApp`, then goes to database config (2) and sets PostrgreSQL (3), then goes to pagination (8) and sets Pagy (2), finally, it goes to `review and confirm` (0) and confirms it (Y).
93
+
94
+ With that file you can do a quick setup with:
95
+
96
+ ```sh
97
+ cat defaults.txt | rails-new-app
98
+ ```
99
+
100
+ This can eventually be used to share complete setups or generate defaults.
101
+
102
+ ### Tests:
103
+
104
+ Run `rake test` or `COVERAGE=true rake test`.
105
+
73
106
  ## Changelogs
74
107
 
75
108
  ### 0.0.1
@@ -84,3 +117,10 @@ Added navigation between menus.
84
117
  - Add a git initial commit
85
118
  - Added new tools: Faker, pagination gems
86
119
  - Bug fixing
120
+
121
+ ### 0.1
122
+ - Refactor screens (ex steps) handling
123
+ - Refactor user input handling to allow easier testing
124
+ - Added tests for multiple screens
125
+ - Bug fixing (Pagy config, incorrect indexing)
126
+ - Added SimpleCov and easier dev setup
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "rake/testtask"
2
+
3
+ Rake::TestTask.new(:test) do |t|
4
+ t.libs << "test"
5
+ t.libs << "lib"
6
+ t.test_files = FileList["test/**/test_*.rb"]
7
+ end
8
+
9
+ task default: :test
data/lib/rails-new-app.rb CHANGED
@@ -15,6 +15,6 @@ module RailsNewApp
15
15
  end
16
16
  ARGV.clear
17
17
 
18
- Runner.new.run(navigation)
18
+ Runner.new(navigation: navigation).run
19
19
  end
20
20
  end
@@ -0,0 +1,16 @@
1
+ module RailsNewApp
2
+ class AuthenticationProcessor < Processor
3
+ def update_gemfile(config)
4
+ case config[:authentication][:key]
5
+ when "devise" then apply_template "devise-gemfile"
6
+ end
7
+ end
8
+
9
+ def configure(config)
10
+ puts "Processing Authentication config"
11
+ case config[:authentication][:key]
12
+ when "devise" then apply_template "devise-config"
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ module RailsNewApp
2
+ class AuthorizationProcessor < Processor
3
+ def update_gemfile(config)
4
+ case config[:authorization][:key]
5
+ when "pundit" then apply_template "pundit-gemfile"
6
+ when "cancancan" then apply_template "cancancan-gemfile"
7
+ end
8
+ end
9
+
10
+ def configure(config)
11
+ puts "Processing Authorization config"
12
+ case config[:authorization][:key]
13
+ when "pundit" then apply_template "pundit-config"
14
+ when "cancancan" then apply_template "cancancan-config"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,57 +1,55 @@
1
- require_relative "steps"
1
+ require_relative "screens"
2
2
  require_relative "processors"
3
3
  require "readline"
4
+ require "byebug"
4
5
 
5
6
  module RailsNewApp
6
- class Runner
7
- # use option: nil to hide the screen from the main menu
8
- SCREENS = [
9
- {option: "1", class: AppNameStep},
10
- {option: "2", class: RailsVersionStep},
11
- {option: "3", class: DatabaseStep},
12
- {option: "4", class: TestRunnerStep},
13
- {option: "5", class: JavaScriptFrameworkStep},
14
- {option: "6", class: RubyLinterStep},
15
- {option: "7", class: TemplateEngineStep},
16
- {option: "8", class: FormBuilderStep},
17
- {option: "9", class: PaginationStep},
18
- {option: nil, class: CodeCoverageStep},
19
- {option: nil, class: TestFactoryStep},
20
- {option: nil, class: TestFakeDataStep}
21
- ].freeze
22
-
23
- def get_screen(option)
24
- case option.to_s
25
- when /\A\d+\z/
26
- SCREENS.find { |x| x[:option] == option.to_s }
27
- else
28
- SCREENS.find { |x| x[:class].key == option.to_sym }
29
- end
30
- end
7
+ # use option: nil to hide the screen from the main menu
8
+ SCREENS = [
9
+ {option: "1", page: 1, class: AppNameScreen},
10
+ {option: "2", page: 1, class: DatabaseScreen},
11
+ {option: "3", page: 1, class: TestRunnerScreen},
12
+ {option: "4", page: 1, class: JavaScriptFrameworkScreen},
13
+ {option: "5", page: 1, class: RubyLinterScreen},
14
+ {option: "6", page: 1, class: TemplateEngineScreen},
15
+ {option: "7", page: 1, class: FormBuilderScreen},
16
+ {option: "8", page: 1, class: PaginationScreen},
17
+ {option: "1", page: 2, class: AuthScreen},
18
+ {option: nil, class: CodeCoverageScreen},
19
+ {option: nil, class: TestFactoryScreen},
20
+ {option: nil, class: TestFakeDataScreen},
21
+ {option: nil, class: AuthenticationScreen},
22
+ {option: nil, class: AuthorizationScreen}
23
+ ].freeze
31
24
 
32
- attr_reader :config
25
+ class Runner
26
+ attr_accessor :config, :current_page, :current_screen, :menu
33
27
 
34
- # entry point
35
- def run(navigation = true)
36
- @config = {navigation: navigation}.tap do |h|
28
+ def initialize(navigation: true)
29
+ @menu = MenuScreen.new SCREENS
30
+ @current_screen = @menu
31
+ @navigation = navigation
32
+ @config = {}.tap do |h|
37
33
  SCREENS.each do |s|
38
34
  kls = s[:class]
39
35
  h[kls.key] = kls.default
40
36
  end
41
37
  end
38
+ end
42
39
 
40
+ # entry point
41
+ def run
43
42
  intro
44
43
 
45
- confirmed =
46
- if navigation
47
- show_menu
44
+ confirmation =
45
+ if @navigation
46
+ start
48
47
  else
49
48
  steps
50
49
  review_and_confirm
51
50
  end
52
51
 
53
- if confirmed
54
- install_rails
52
+ if confirmation == :finish
55
53
  rails_new
56
54
  process_config
57
55
  end_message
@@ -62,132 +60,71 @@ module RailsNewApp
62
60
  end
63
61
  end
64
62
 
65
- def clear
66
- system("clear")
67
- end
68
-
69
63
  def intro
70
64
  clear
71
65
  puts "Let's create a new Rails app step by step"
72
66
  end
73
67
 
74
- def print_screens
75
- SCREENS.each do |s|
76
- next if s[:option].nil?
77
-
78
- screen_name = s[:class].clean_name
79
- puts "#{s[:option]} : #{screen_name}"
80
- end
81
- puts "0 : Review and confirm"
82
- puts ""
83
- puts "Type the number of the menu and press enter:"
68
+ def show_current_screen
69
+ puts current_screen.screen_text
84
70
  end
85
71
 
86
- def show_menu
87
- print_screens
72
+ def start
73
+ next_do = nil
74
+
88
75
  loop do
76
+ show_current_screen
89
77
  option = gets.chomp.strip
90
- if option == "0"
91
- case review_and_confirm
92
- when :yes then return true
93
- when :no then return false
94
- end
95
- clear
96
- print_screens
97
- else
98
- show_screen(option)
99
- end
100
- end
101
- end
102
78
 
103
- def show_screen(option)
104
- if (s = get_screen(option))
105
- screen_obj = s[:class].new
106
- config[s[:class].key] = screen_obj.run(config)
79
+ next_do = process_user_input(option)
80
+ case next_do
81
+ when :finish, :abort then break
82
+ end
107
83
  clear
108
- screen_obj.next_step ? show_screen(screen_obj.next_step) : print_screens
109
- else
110
- puts "Invalid option, select a category:"
111
84
  end
85
+
86
+ next_do
112
87
  end
113
88
 
114
- def steps
115
- config[:app_name] = AppNameStep.run(config)
116
- config[:rails_version] = RailsVersionStep.run(config)
117
- config[:database] = DatabaseStep.run(config)
118
- config[:test_runner] = TestRunnerStep.run(config)
89
+ def process_user_input(option)
90
+ next_step, new_config = @current_screen.process_user_input(option)
119
91
 
120
- if config[:test_runner][:key] != ""
121
- config[:code_coverage] = CodeCoverageStep.run(config)
122
- config[:test_factory] = TestFactoryStep.run(config)
123
- config[:test_fake_data] = TestFakeDataStep.run(config)
92
+ if new_config
93
+ @config[@current_screen.class.key] = new_config
124
94
  end
125
95
 
126
- config[:js_framework] = JavaScriptFrameworkStep.run(config)
127
- config[:ruby_linter] = RubyLinterStep.run(config)
128
- config[:template_engine] = TemplateEngineStep.run(config)
129
- config[:form_builder] = FormBuilderStep.run(config)
130
- config[:pagination] = PaginationStep.run(config)
131
- end
132
-
133
- def review_and_confirm
134
- clear
135
- rails_ver = config[:rails_version]
136
- rails_ver = "Using latest installed Rails version" if rails_ver == ""
137
-
138
- puts <<~REVIEW
139
- ===== New Rails app config =====
140
-
141
- App name: #{config[:app_name]}
142
- Ruby version: #{RUBY_VERSION}
143
- Rails version: #{rails_ver}
144
- Database: #{config[:database]}
145
- Test runner: #{config[:test_runner]}
146
- Code coverage: #{config[:code_coverage]}
147
- Test factories: #{config[:test_factory]}
148
- Test fake data: #{config[:test_fake_data]}
149
- JS framework: #{config[:java_script_framework]}
150
- Ruby Linter: #{config[:ruby_linter]}
151
- Template engine: #{config[:template_engine]}
152
- Form builder: #{config[:form_builder]}
153
- Pagination: #{config[:pagination]}
154
-
155
- REVIEW
156
-
157
- message = "Type 'Y(es)' to confirm, 'B(ack) to go back, or 'N(o)' to abort"
158
- if config[:app_name] == ""
159
- puts <<~WARNING
160
- =====================================
161
- App name is required
162
- =====================================
163
-
164
- WARNING
165
- message.gsub!("Type 'Y(es)' to confirm, ", "Type ")
96
+ case next_step
97
+ when :menu then @current_screen = @menu
98
+ when :review_and_confirm then @current_screen = ReviewAndConfirmScreen.new(config)
99
+ when :finish, :abort, :rerender then next_step
100
+ else
101
+ @current_screen = get_screen(next_step).new(config)
166
102
  end
103
+ end
167
104
 
168
- loop do
169
- puts message
170
- answer = gets.chomp.strip
171
- return :yes if /\A*Y(es)?\z/i.match?(answer)
172
- return :back if /\A*B(ack)?\z/i.match?(answer)
173
- return :no if /\A*N(o)?\z/i.match?(answer)
105
+ def steps
106
+ config[:app_name] = AppNameScreen.run(config)
107
+ config[:database] = DatabaseScreen.run(config)
108
+ config[:test_runner] = TestRunnerScreen.run(config)
174
109
 
175
- puts "Invalid option."
110
+ if config[:test_runner][:key] != ""
111
+ config[:code_coverage] = CodeCoverageScreen.run(config)
112
+ config[:test_factory] = TestFactoryScreen.run(config)
113
+ config[:test_fake_data] = TestFakeDataScreen.run(config)
176
114
  end
177
- end
178
115
 
179
- def install_rails
180
- return if config[:rails_version] == ""
181
- # install the require rails version if needed
182
- puts "Verifying and installing Rails #{config[:rails_ven]}"
183
- `gem install rails -v#{config[:rails_version]}`
116
+ config[:js_framework] = JavaScriptFrameworkScreen.run(config)
117
+ config[:ruby_linter] = RubyLinterScreen.run(config)
118
+ config[:template_engine] = TemplateEngineScreen.run(config)
119
+ config[:form_builder] = FormBuilderScreen.run(config)
120
+ config[:pagination] = PaginationScreen.run(config)
184
121
  end
185
122
 
186
123
  def rails_new
187
124
  puts "Running Rails new"
188
125
  command = build_rails_new_command
189
126
  puts command
190
- system(command)
127
+ run_cmnd(command)
191
128
  end
192
129
 
193
130
  def process_config
@@ -202,11 +139,13 @@ module RailsNewApp
202
139
  TemplateEngineProcessor,
203
140
  FormBuilderProcessor,
204
141
  RubyLinterProcessor,
205
- PaginationProcessor
142
+ PaginationProcessor,
143
+ AuthorizationProcessor,
144
+ AuthenticationProcessor
206
145
  ].each { |p| p.update_gemfile(config) }
207
146
 
208
147
  # install gems
209
- system("bundle install")
148
+ run_cmnd("bundle install")
210
149
 
211
150
  # configure each gem
212
151
  [
@@ -215,7 +154,9 @@ module RailsNewApp
215
154
  TestFactoryProcessor,
216
155
  FormBuilderProcessor,
217
156
  RubyLinterProcessor,
218
- PaginationProcessor
157
+ PaginationProcessor,
158
+ AuthorizationProcessor,
159
+ AuthenticationProcessor
219
160
  ].each { |p| p.configure(config) }
220
161
 
221
162
  after_create
@@ -235,19 +176,15 @@ module RailsNewApp
235
176
  puts "Aborted"
236
177
  end
237
178
 
238
- private
239
-
240
179
  # final step and creation
241
180
  def build_rails_new_command
242
181
  ["rails"].tap do |ar|
243
- # use specific Rails version
244
- ar << "_#{config[:rails_version]}_" if config[:rails_version] != ""
245
182
  # new command
246
183
  ar << "new"
247
184
  # use desired database
248
- ar << "--database=#{config[:database][:key]}" if config[:database][:in_rails_new]
185
+ ar << "--database=#{config[:database][:key]}" if config[:database][:in_rails_new] && !config[:database][:is_default]
249
186
  # ignore test if not minitest
250
- ar << "--skip_test" if config[:test_runner][:key] != "minitest"
187
+ ar << "--skip-test" if config[:test_runner][:key] != "minitest"
251
188
  # use desired js framework
252
189
  ar << "--webpack=#{config[:java_script_framework][:key]}" if config[:java_script_framework][:in_rails_new]
253
190
  # ar << "--skip-javascript"
@@ -258,14 +195,28 @@ module RailsNewApp
258
195
 
259
196
  def fix_code_style
260
197
  case config[:ruby_linter][:key]
261
- when "rubocop" then system("rubocop -A")
262
- when "standardrb" then system("standardrb --fix")
198
+ when "rubocop" then run_cmnd("rubocop -A")
199
+ when "standardrb" then run_cmnd("standardrb --fix")
263
200
  end
264
201
  end
265
202
 
266
203
  def initial_commit
267
- system("git add .")
268
- system("git commit -a -m 'Initial commit'")
204
+ run_cmnd("git add .")
205
+ run_cmnd("git commit -a -m 'Initial commit'")
206
+ end
207
+
208
+ private
209
+
210
+ def clear
211
+ run_cmnd("clear")
212
+ end
213
+
214
+ def run_cmnd(cmd)
215
+ system(cmd) unless ENV["env"] == "test"
216
+ end
217
+
218
+ def get_screen(key)
219
+ SCREENS.find { |x| x[:class].key == key.to_sym }[:class]
269
220
  end
270
221
  end
271
222
  end