Class: Reins::Cli
- Inherits:
-
Thor
- Object
- Thor
- Reins::Cli
- Defined in:
- lib/reins/cli.rb
Instance Method Summary collapse
- #console ⇒ Object
- #db_create ⇒ Object
- #db_drop ⇒ Object
- #db_migrate ⇒ Object
- #db_rollback(steps = "1") ⇒ Object
- #db_schema_dump ⇒ Object
- #generate(type, name, *fields) ⇒ Object
- #new(name) ⇒ Object
- #routes ⇒ Object
- #server ⇒ Object
- #test ⇒ Object
Instance Method Details
#console ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/reins/cli.rb', line 77 def console unless File.exist?("config/application.rb") warn "config/application.rb not found in #{Dir.pwd}" exit 1 end load "config/application.rb" Reins::Application.subclasses.last&.new load "config/routes.rb" if File.exist?("config/routes.rb") require "irb" IRB.start end |
#db_create ⇒ Object
93 94 95 96 97 98 |
# File 'lib/reins/cli.rb', line 93 def db_create Reins::DatabaseConfig.load! FileUtils.mkdir_p(File.dirname(Reins::Database.path)) Reins::Database.connection.execute("SELECT 1") puts "Created #{Reins::Database.path}" end |
#db_drop ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/reins/cli.rb', line 102 def db_drop Reins::DatabaseConfig.load! path = Reins::Database.path Reins::Database.reset! FileUtils.rm_f(path) puts "Dropped #{path}" end |
#db_migrate ⇒ Object
112 113 114 115 |
# File 'lib/reins/cli.rb', line 112 def db_migrate Reins::DatabaseConfig.load! Reins::Migrator.new.run end |
#db_rollback(steps = "1") ⇒ Object
119 120 121 122 |
# File 'lib/reins/cli.rb', line 119 def db_rollback(steps = "1") Reins::DatabaseConfig.load! Reins::Migrator.new.rollback(Integer(steps)) end |
#db_schema_dump ⇒ Object
126 127 128 129 130 |
# File 'lib/reins/cli.rb', line 126 def db_schema_dump Reins::DatabaseConfig.load! Reins::Schema.dump puts "Wrote db/schema.rb" end |
#generate(type, name, *fields) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/reins/cli.rb', line 55 def generate(type, name, *fields) case type when "migration" generate_migration(name, fields) when "controller" Reins::Generators::ControllerGenerator.new(name, fields).run when "model" Reins::Generators::ModelGenerator.new(name, fields).run when "scaffold" Reins::Generators::ScaffoldGenerator.new(name, fields).run else warn "unknown generator: #{type}" exit 1 end end |
#new(name) ⇒ Object
9 10 11 12 13 |
# File 'lib/reins/cli.rb', line 9 def new(name) Reins::Generators::AppGenerator.new(name).run puts "Created #{name}/" puts "Now run: cd #{name} && bin/setup" end |
#routes ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/reins/cli.rb', line 36 def routes config = File.join(Dir.pwd, "config.ru") unless File.exist?(config) warn "config.ru not found in #{Dir.pwd}" exit 1 end Rack::Builder.parse_file(config) app = Reins::Application.instances.last if app.nil? || app.routes.nil? warn "No Reins::Application with routes was loaded from config.ru" exit 1 end print_routes_table(app.routes.rules) end |
#server ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/reins/cli.rb', line 16 def server root = File.(Dir.pwd.to_s) config = "#{root}/config.ru" app = Rack::Builder.load_file(config) server = Puma::Server.new(app) server.add_tcp_listener('0.0.0.0', 8000) trap('INT') do server.stop puts "\nServer stopped." exit end puts "Serving files from #{root} on http://localhost:8000" server.run.join end |
#test ⇒ Object
72 73 74 |
# File 'lib/reins/cli.rb', line 72 def test(*) system("bundle", "exec", "rspec", *) end |