Class: RubyAPI::CLI
- Inherits:
-
Object
- Object
- RubyAPI::CLI
- Defined in:
- lib/fastrb/cli.rb
Class Method Summary collapse
- .config_ru_content ⇒ Object
- .gemfile_content(name) ⇒ Object
- .hello_spec_content ⇒ Object
- .invoke(args) ⇒ Object
- .main_rb_content ⇒ Object
- .new_project(name) ⇒ Object
- .readme_content(name) ⇒ Object
- .routes_rb_content ⇒ Object
- .spec_helper_content ⇒ Object
- .start_server ⇒ Object
Class Method Details
.config_ru_content ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/fastrb/cli.rb', line 66 def self.config_ru_content " require_relative \"app/main\"\n require_relative \"app/routes\"\n\n run App.new\n RUBY\nend\n" |
.gemfile_content(name) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/fastrb/cli.rb', line 56 def self.gemfile_content(name) " source \"https://rubygems.org\"\n\n gem \"fastrb\", \"~> \#{RubyAPI::VERSION}\"\n gem \"rackup\"\n gem \"puma\"\n GEMFILE\nend\n" |
.hello_spec_content ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/fastrb/cli.rb', line 122 def self.hello_spec_content " require \"spec_helper\"\n\n RSpec.describe \"GET /hello\" do\n include Rack::Test::Methods\n\n def app\n App.new\n end\n\n it \"returns hello world\" do\n get \"/hello\"\n expect(last_response.status).to eq(200)\n expect(JSON.parse(last_response.body)[\"message\"]).to eq(\"Hello World\")\n end\n end\n RUBY\nend\n" |
.invoke(args) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/fastrb/cli.rb', line 6 def self.invoke(args) command = args[0] name = args[1] case command when "new" new_project(name) when "server" start_server when "version" puts "fastrb #{VERSION}" else puts "Usage: fastrb <command> [options]" puts "" puts "Commands:" puts " new <name> Create a new FastRb project" puts " server Start the server (Falcon/Puma)" puts " version Show version" exit 1 end end |
.main_rb_content ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fastrb/cli.rb', line 75 def self.main_rb_content " require \"fastrb\"\n\n class App < RubyAPI::App\n def initialize\n super do\n # Middleware\n # use MyMiddleware\n\n # Routes\n include Routes\n end\n end\n end\n RUBY\nend\n" |
.new_project(name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastrb/cli.rb', line 28 def self.new_project(name) puts "Creating new FastRb project: #{name}" FileUtils.mkdir_p(name) FileUtils.mkdir_p("#{name}/app") FileUtils.mkdir_p("#{name}/config/environments") FileUtils.mkdir_p("#{name}/public") FileUtils.mkdir_p("#{name}/spec/unit") FileUtils.mkdir_p("#{name}/spec/requests") File.write("#{name}/Gemfile", gemfile_content(name)) File.write("#{name}/config.ru", config_ru_content) File.write("#{name}/app/main.rb", main_rb_content) File.write("#{name}/app/routes.rb", routes_rb_content) File.write("#{name}/.rspec", ".rspec") File.write("#{name}/spec/spec_helper.rb", spec_helper_content) File.write("#{name}/spec/requests/hello_spec.rb", hello_spec_content) File.write("#{name}/README.md", readme_content(name)) puts "Done! cd #{name} && bundle install && fastrb server" end |
.readme_content(name) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/fastrb/cli.rb', line 142 def self.readme_content(name) " # \#{name}\n\n A FastRb application.\n\n ## Setup\n\n bundle install\n\n ## Running\n\n fastrb server\n\n ## Testing\n\n bundle exec rspec\n MARKDOWN\nend\n" |
.routes_rb_content ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fastrb/cli.rb', line 93 def self.routes_rb_content " module Routes\n def self.included(base)\n base.get \"/hello\" do\n { message: \"Hello World\" }\n end\n end\n end\n RUBY\nend\n" |
.spec_helper_content ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fastrb/cli.rb', line 105 def self.spec_helper_content " require \"fastrb\"\n require \"rack/test\"\n\n RSpec.configure do |config|\n config.expect_with :rspec do |expectations|\n expectations.include_chain_clauses_in_custom_matcher_descriptions = true\n end\n\n config.mock_with :rspec do |mocks|\n mocks.verify_partial_doubles = true\n end\n end\n RUBY\nend\n" |
.start_server ⇒ Object
50 51 52 |
# File 'lib/fastrb/cli.rb', line 50 def self.start_server require_relative "../../config.ru" end |