class RailsNewApp::Runner
Attributes
config[RW]
current_page[RW]
current_screen[RW]
Public Class Methods
new(navigation: true)
click to toggle source
# File lib/rails-new-app/runner.rb, line 28 def initialize(navigation: true) @menu = MenuScreen.new SCREENS @current_screen = @menu @navigation = navigation @config = {}.tap do |h| SCREENS.each do |s| kls = s[:class] h[kls.key] = kls.default end end end
Public Instance Methods
aborted_message()
click to toggle source
# File lib/rails-new-app/runner.rb, line 175 def aborted_message puts "Aborted" end
after_create()
click to toggle source
# File lib/rails-new-app/runner.rb, line 166 def after_create fix_code_style initial_commit end
build_rails_new_command()
click to toggle source
final step and creation
# File lib/rails-new-app/runner.rb, line 180 def build_rails_new_command ["rails"].tap do |ar| # new command ar << "new" # use desired database ar << "--database=#{config[:database][:key]}" if config[:database][:in_rails_new] && !config[:database][:is_default] # ignore test if not minitest ar << "--skip-test" if config[:test_runner][:key] != "minitest" # use desired js framework ar << "--webpack=#{config[:java_script_framework][:key]}" if config[:java_script_framework][:in_rails_new] # ar << "--skip-javascript" # add app name ar << config[:app_name] end.join(" ") end
end_message()
click to toggle source
# File lib/rails-new-app/runner.rb, line 171 def end_message puts "Your new Rails app is ready!" end
fix_code_style()
click to toggle source
# File lib/rails-new-app/runner.rb, line 196 def fix_code_style case config[:ruby_linter][:key] when "rubocop" then run_cmnd("rubocop -A") when "standardrb" then run_cmnd("standardrb --fix") end end
initial_commit()
click to toggle source
# File lib/rails-new-app/runner.rb, line 203 def initial_commit run_cmnd("git add .") run_cmnd("git commit -a -m 'Initial commit'") end
intro()
click to toggle source
# File lib/rails-new-app/runner.rb, line 63 def intro clear puts "Let's create a new Rails app step by step" end
process_config()
click to toggle source
# File lib/rails-new-app/runner.rb, line 130 def process_config # cd into rails app Dir.chdir(config[:app_name]) do # add different gems [ TestRunnerProcessor, CodeCoverageProcessor, TestFactoryProcessor, TestFakeDataProcessor, TemplateEngineProcessor, FormBuilderProcessor, RubyLinterProcessor, PaginationProcessor, AuthorizationProcessor, AuthenticationProcessor ].each { |p| p.update_gemfile(config) } # install gems run_cmnd("bundle install") # configure each gem [ TestRunnerProcessor, CodeCoverageProcessor, TestFactoryProcessor, FormBuilderProcessor, RubyLinterProcessor, PaginationProcessor, AuthorizationProcessor, AuthenticationProcessor ].each { |p| p.configure(config) } after_create end end
process_user_input(option)
click to toggle source
# File lib/rails-new-app/runner.rb, line 89 def process_user_input(option) next_step, new_config = @current_screen.process_user_input(option) if new_config @config[@current_screen.class.key] = new_config end case next_step when :menu then @current_screen = @menu when :review_and_confirm then @current_screen = ReviewAndConfirmScreen.new(config) when :finish, :abort, :rerender then next_step else @current_screen = get_screen(next_step).new(config) end end
rails_new()
click to toggle source
# File lib/rails-new-app/runner.rb, line 123 def rails_new puts "Running Rails new" command = build_rails_new_command puts command run_cmnd(command) end
run()
click to toggle source
entry point
# File lib/rails-new-app/runner.rb, line 41 def run intro confirmation = if @navigation start else steps review_and_confirm end if confirmation == :finish rails_new process_config end_message 0 else aborted_message 1 end end
show_current_screen()
click to toggle source
# File lib/rails-new-app/runner.rb, line 68 def show_current_screen puts current_screen.screen_text end
start()
click to toggle source
# File lib/rails-new-app/runner.rb, line 72 def start next_do = nil loop do show_current_screen option = gets.chomp.strip next_do = process_user_input(option) case next_do when :finish, :abort then break end clear end next_do end
steps()
click to toggle source
# File lib/rails-new-app/runner.rb, line 105 def steps config[:app_name] = AppNameScreen.run(config) config[:database] = DatabaseScreen.run(config) config[:test_runner] = TestRunnerScreen.run(config) if config[:test_runner][:key] != "" config[:code_coverage] = CodeCoverageScreen.run(config) config[:test_factory] = TestFactoryScreen.run(config) config[:test_fake_data] = TestFakeDataScreen.run(config) end config[:js_framework] = JavaScriptFrameworkScreen.run(config) config[:ruby_linter] = RubyLinterScreen.run(config) config[:template_engine] = TemplateEngineScreen.run(config) config[:form_builder] = FormBuilderScreen.run(config) config[:pagination] = PaginationScreen.run(config) end
Private Instance Methods
clear()
click to toggle source
# File lib/rails-new-app/runner.rb, line 210 def clear run_cmnd("clear") end
get_screen(key)
click to toggle source
# File lib/rails-new-app/runner.rb, line 218 def get_screen(key) SCREENS.find { |x| x[:class].key == key.to_sym }[:class] end
run_cmnd(cmd)
click to toggle source
# File lib/rails-new-app/runner.rb, line 214 def run_cmnd(cmd) system(cmd) unless ENV["env"] == "test" end