roda-project 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/roda/project/bin/generators/migration.rb +2 -0
- data/lib/roda/project/bin/generators/routes.rb +29 -2
- data/lib/roda/project/cli.rb +2 -1
- data/lib/roda/project/main_context.rb +2 -0
- data/lib/roda/project/templates/base/app/app.rb.erb +1 -1
- data/lib/roda/project/templates/base/scaffold/Gemfile.erb +1 -0
- data/lib/roda/project/templates/base/scaffold/bin/roda.erb +67 -2
- data/lib/roda/project/version.rb +1 -1
- data/lib/roda/project.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bca56b06faeb347730f67dce564950b0f3fb9a2e0271820551f96752678121e1
|
|
4
|
+
data.tar.gz: 1233a11fa1418c2492e956e79ea8d2f74db2689ce902e3fad04159245fc8a451
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0f42c3f7152377f79986fbba0fb2c2cfa7cb6c583c68ca05c9f78463c44e8445ad9c76a87e506302718f8d07c1ea97b195359878b21357b89b005e329de45e35
|
|
7
|
+
data.tar.gz: 23ce0cb9af858542d5a213e5e934a97619ea3b4be93b3379b06a04b63dabaa2019d18cc5e4fcf847581bad81a1c9de4eed81efa660367827b6627cbee57a6158
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# rubocop:disable Layout/HeredocIndentation
|
|
1
2
|
class Roda
|
|
2
3
|
module Project
|
|
3
4
|
module Bin
|
|
@@ -12,6 +13,7 @@ class Roda
|
|
|
12
13
|
generate_routes
|
|
13
14
|
generate_views
|
|
14
15
|
generate_tests
|
|
16
|
+
print_nested_branch_reminder
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
private
|
|
@@ -24,9 +26,19 @@ class Roda
|
|
|
24
26
|
" r.#{method} \"#{name}\" do#{view_line}\n end"
|
|
25
27
|
end.join("\n\n")
|
|
26
28
|
|
|
29
|
+
hash_branch_header = if branch_name.include?("/")
|
|
30
|
+
parts = branch_name.split("/")
|
|
31
|
+
sub_path = parts[0..-2].join("/")
|
|
32
|
+
namespace = sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
33
|
+
branch_segment = parts.last
|
|
34
|
+
"hash_branch #{namespace}, \"#{branch_segment}\" do |r|"
|
|
35
|
+
else
|
|
36
|
+
"hash_branch \"#{branch_name}\" do |r|"
|
|
37
|
+
end
|
|
38
|
+
|
|
27
39
|
content = <<~RUBY
|
|
28
40
|
class #{@context.const_project_name}
|
|
29
|
-
|
|
41
|
+
#{hash_branch_header}
|
|
30
42
|
#{route_definitions}
|
|
31
43
|
end
|
|
32
44
|
end
|
|
@@ -92,14 +104,29 @@ class Roda
|
|
|
92
104
|
end
|
|
93
105
|
|
|
94
106
|
def routes_list
|
|
95
|
-
@routes_list ||= @args[1
|
|
107
|
+
@routes_list ||= @args[1..]
|
|
96
108
|
end
|
|
97
109
|
|
|
98
110
|
def branch_name
|
|
99
111
|
@branch_name ||= @args[0]
|
|
100
112
|
end
|
|
113
|
+
|
|
114
|
+
def print_nested_branch_reminder
|
|
115
|
+
return unless branch_name.include?("/")
|
|
116
|
+
|
|
117
|
+
parts = branch_name.split("/")
|
|
118
|
+
sub_path = parts[0..-2].join("/")
|
|
119
|
+
namespace = sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
120
|
+
|
|
121
|
+
puts "\ndont forget to add:\n\n" \
|
|
122
|
+
"autoload_hash_branch_dir(#{namespace}, \"./app/routes/#{sub_path}\")\n\n" \
|
|
123
|
+
"route do |r|\n" \
|
|
124
|
+
" r.on(\"#{sub_path}\") { r.hash_branches(#{namespace}) }\n" \
|
|
125
|
+
"end\n"
|
|
126
|
+
end
|
|
101
127
|
end
|
|
102
128
|
end
|
|
103
129
|
end
|
|
104
130
|
end
|
|
105
131
|
end
|
|
132
|
+
# rubocop:enable Layout/HeredocIndentation
|
data/lib/roda/project/cli.rb
CHANGED
|
@@ -22,8 +22,9 @@ class Roda
|
|
|
22
22
|
puts "$ cd #{@context.project_name} && bundle"
|
|
23
23
|
if @context.database?
|
|
24
24
|
unless @context.sqlite?
|
|
25
|
-
puts "\n* create your database\n"
|
|
26
25
|
puts "\n* put your dev database credentials in app/config/config.rb\n"
|
|
26
|
+
puts "\n* create your database\n"
|
|
27
|
+
puts "$ bin/roda db create"
|
|
27
28
|
end
|
|
28
29
|
puts "\nmigrate the database (use RACK_ENV to migrate 'test' or 'production' environments):\n\n"
|
|
29
30
|
puts "$ bin/roda db migrate"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
class <%= context.const_project_name %> < Roda
|
|
2
2
|
# Routing<% if context.fullstack? %>
|
|
3
|
-
plugin :
|
|
3
|
+
plugin :hash_branch_view_namespace<% end %>
|
|
4
4
|
plugin :autoload_hash_branches
|
|
5
5
|
autoload_hash_branch_dir("./app/routes")
|
|
6
6
|
plugin :all_verbs
|
|
@@ -6,9 +6,8 @@ class Db < Thor
|
|
|
6
6
|
desc "migrate", "Migrate the database. Optional: provide target version, e.g., 'roda db:migrate 1'"
|
|
7
7
|
option :target, type: :numeric, aliases: "-t", desc: "provide target version"
|
|
8
8
|
def migrate
|
|
9
|
+
require_db_deps
|
|
9
10
|
require_relative "../boot"
|
|
10
|
-
require "sequel"
|
|
11
|
-
require "sequel/extensions/migration"
|
|
12
11
|
|
|
13
12
|
Sequel.extension :migration
|
|
14
13
|
db = Providers::DB::Conn.get
|
|
@@ -19,6 +18,72 @@ class Db < Thor
|
|
|
19
18
|
end
|
|
20
19
|
puts "* database migration complete."
|
|
21
20
|
end
|
|
21
|
+
<% if context.sqlite? %>
|
|
22
|
+
desc "create", "Create the database"
|
|
23
|
+
def create
|
|
24
|
+
require_db_deps
|
|
25
|
+
path = parse_sqlite_path(Config.get[:db][:url])
|
|
26
|
+
FileUtils.mkdir_p(File.dirname(path))
|
|
27
|
+
Sequel.connect("sqlite://#{path}") rescue nil
|
|
28
|
+
puts "* create database #{path} ✓"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
desc "drop", "Drop the database"
|
|
32
|
+
def drop
|
|
33
|
+
require_db_deps
|
|
34
|
+
path = parse_sqlite_path(Config.get[:db][:url])
|
|
35
|
+
File.delete(path) if File.exist?(path)
|
|
36
|
+
puts "* drop database #{path} ✓"
|
|
37
|
+
end
|
|
38
|
+
<% else %>
|
|
39
|
+
[:drop, :create].each do |action|
|
|
40
|
+
desc action.to_s, "#{action.capitalize} the database"
|
|
41
|
+
define_method(action) do
|
|
42
|
+
require_db_deps
|
|
43
|
+
require_relative "../app/config/config"<% if context.postgresql? %>
|
|
44
|
+
db_config =
|
|
45
|
+
PG::Connection
|
|
46
|
+
.conninfo_parse(Config.get[:db][:url])
|
|
47
|
+
.each_with_object({}) { |h, o|
|
|
48
|
+
o[h[:keyword].to_sym] = h[:val] if h[:val]
|
|
49
|
+
}
|
|
50
|
+
ok = system("PGPASSWORD='#{db_config[:password]}' #{action}db -h #{db_config[:host]} -p #{db_config[:port]} -U #{db_confi
|
|
51
|
+
g[:user]} #{db_config[:dbname]}")<% end %><% if context.mysql? %>
|
|
52
|
+
uri = URI.parse(Config.get[:db][:url])
|
|
53
|
+
db_config = {
|
|
54
|
+
host: uri.host,
|
|
55
|
+
port: uri.port,
|
|
56
|
+
user: uri.user,
|
|
57
|
+
password: uri.password,
|
|
58
|
+
dbname: uri.path.tr('/', '') # removes leading slash
|
|
59
|
+
}
|
|
60
|
+
sql = action == :create ?
|
|
61
|
+
"CREATE DATABASE IF NOT EXISTS `#{db_config[:dbname]}`;" :
|
|
62
|
+
"DROP DATABASE IF EXISTS `#{db_config[:dbname]}`;"
|
|
63
|
+
flags = []
|
|
64
|
+
flags << "-h#{db_config[:host]}" if db_config[:host]
|
|
65
|
+
flags << "-P#{db_config[:port]}" if db_config[:port]
|
|
66
|
+
flags << "-u#{db_config[:user]}" if db_config[:user]
|
|
67
|
+
env = { "MYSQL_PWD" => db_config[:password] }.compact
|
|
68
|
+
ok = system(env, "mysql", *flags, "-e", sql)<% end %>
|
|
69
|
+
puts "* #{action} database #{db_config[:dbname]} ✓" if ok
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
<% end %>
|
|
73
|
+
private
|
|
74
|
+
<% if context.sqlite? %>
|
|
75
|
+
def parse_sqlite_path(url)
|
|
76
|
+
uri = URI.parse(url)
|
|
77
|
+
File.expand_path(uri.host ? File.join(uri.host, uri.path) : uri.path, Dir.pwd)
|
|
78
|
+
end
|
|
79
|
+
<% end %>
|
|
80
|
+
def require_db_deps
|
|
81
|
+
require_relative "../boot"
|
|
82
|
+
require "sequel"
|
|
83
|
+
require "sequel/extensions/migration"
|
|
84
|
+
require "<%= context.db_gem %>"<% if context.mysql? %>
|
|
85
|
+
require "uri"<% end %>
|
|
86
|
+
end
|
|
22
87
|
end
|
|
23
88
|
<% end %>
|
|
24
89
|
class CLI < Thor
|
data/lib/roda/project/version.rb
CHANGED
data/lib/roda/project.rb
CHANGED
|
@@ -61,8 +61,8 @@ require_relative "project/generator"
|
|
|
61
61
|
require_relative "project/cli"
|
|
62
62
|
# Generators
|
|
63
63
|
require_relative "project/bin/generator"
|
|
64
|
-
require_relative
|
|
65
|
-
require_relative
|
|
64
|
+
require_relative "project/bin/generators/migration"
|
|
65
|
+
require_relative "project/bin/generators/routes"
|
|
66
66
|
require_relative "project/bin/generators"
|
|
67
67
|
# Version
|
|
68
68
|
require_relative "project/version"
|