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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 235c82e6d3bae7eebc1b331a1d74272222f3e5a6a0957536a68b4d766f82a34c
4
- data.tar.gz: e8ee5c63d19ad043c2f0c55647b6534b6bc0186d2a92e67335ec9319e9a7c93a
3
+ metadata.gz: bca56b06faeb347730f67dce564950b0f3fb9a2e0271820551f96752678121e1
4
+ data.tar.gz: 1233a11fa1418c2492e956e79ea8d2f74db2689ce902e3fad04159245fc8a451
5
5
  SHA512:
6
- metadata.gz: d371e15403ffec2a67ff2577a2044d671334380af4188b3b2cd828ef61f181a48ba30e30d2640042c6d534d41e4fba9acaa5aa553e27d1e50de7946f054c2762
7
- data.tar.gz: 9413055aab700d47ecf17442ab7e2fff22d6db8d0fb7a3a94e9237b16a2b718763a14453f1b1eb36230561068e9c66c10c556478ee3f46e909d8177241028034
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
@@ -47,3 +48,4 @@ class Roda
47
48
  end
48
49
  end
49
50
  end
51
+ # rubocop:enable Layout/HeredocIndentation
@@ -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
- hash_branch "#{branch_name}" do |r|
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..-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
@@ -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,3 +1,4 @@
1
+ # rubocop:disable Layout/HeredocIndentation
1
2
  class Roda
2
3
  module Project
3
4
  class MainContext
@@ -155,3 +156,4 @@ class Roda
155
156
  end
156
157
  end
157
158
  end
159
+ # rubocop:enable Layout/HeredocIndentation
@@ -1,6 +1,6 @@
1
1
  class <%= context.const_project_name %> < Roda
2
2
  # Routing<% if context.fullstack? %>
3
- plugin :hash_branch_view_subdir<% end %>
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
@@ -23,6 +23,7 @@ gem "puma"
23
23
 
24
24
  # Views
25
25
  gem 'roda-assets_manifest'
26
+ gem 'roda-hash_branch_view_namespace'
26
27
  <% end %>
27
28
  # Performance
28
29
  gem "oj"
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Roda
4
4
  module Project
5
- VERSION = "0.1.7"
5
+ VERSION = "0.1.9"
6
6
  end
7
7
  end
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 'project/bin/generators/migration'
65
- require_relative 'project/bin/generators/routes'
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"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira