Class: RailsNew::CLI
- Inherits:
-
Thor::Group
- Object
- Thor::Group
- RailsNew::CLI
- Defined in:
- lib/rails_new/cli.rb
Instance Method Summary collapse
- #exit_on_failure? ⇒ Boolean
- #parse_template_data ⇒ Object
- #request_template_data ⇒ Object
- #run_template ⇒ Object
Instance Method Details
#exit_on_failure? ⇒ Boolean
71 72 73 |
# File 'lib/rails_new/cli.rb', line 71 def exit_on_failure? true end |
#parse_template_data ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/rails_new/cli.rb', line 34 def parse_template_data @template_data = JSON.parse(@response.body)['template'] @git_repository = @template_data['git_repository'] @git_branch = @template_data['git_branch'] @main_file_location = @template_data["main_file_location"] @arguments = build_arguments_array(@template_data['arguments']) end |
#request_template_data ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rails_new/cli.rb', line 22 def request_template_data url = RailsNew::Api.template_url_for(template_key) say "Fetching template data from ", :green, false say url, :blue @response = HTTParty.get(url) if @response.code != 200 raise "The response of the server to #{@response.request.uri} was not 200." end end |
#run_template ⇒ Object
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 |
# File 'lib/rails_new/cli.rb', line 42 def run_template Dir.mktmpdir do |temp_dir| template_location = Pathname.new(temp_dir).join(@main_file_location).to_s say "Cloning git repository ", :green, false say @git_repository, :blue clone_command = RailsNew::Command.new("git", "clone", "-b", @git_branch, @git_repository, temp_dir) clone_command.run rails_command = RailsNew::Command.new( "rails", "new", @app_name, "-m", template_location, *@arguments, *extra_rails_arguments ) say "The following command will be executed:", :green, false puts "\n\n" say rails_command.to_s, :blue puts if yes? "Is this command safe?" say "Executing template", :green rails_command.run else say "Aborted command. Please review the template #{template_key}.", :red exit(1) end end end |