roda-project 0.1.14 → 0.1.16
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/routes.rb +55 -19
- data/lib/roda/project/bin/generators/service.rb +4 -6
- data/lib/roda/project/templates/base/app/app.rb.erb +3 -2
- data/lib/roda/project/templates/base/minimal/boot.rb +2 -2
- data/lib/roda/project/templates/base/scaffold/Gemfile.erb +0 -1
- data/lib/roda/project/templates/base/scaffold/boot.rb.erb +17 -5
- data/lib/roda/project/templates/tests/minitest/spec/app/app_spec.rb.erb +3 -3
- data/lib/roda/project/templates/tests/minitest/spec/app/routes/foo_spec.rb.erb +9 -0
- data/lib/roda/project/templates/tests/minitest/spec/spec_helper.rb.erb +1 -1
- data/lib/roda/project/templates/tests/rspec/spec/app/app_spec.rb.erb +3 -3
- data/lib/roda/project/templates/tests/rspec/spec/app/routes/foo_spec.rb.erb +9 -0
- data/lib/roda/project/templates/tests/rspec/spec/spec_helper.rb.erb +1 -1
- data/lib/roda/project/version.rb +1 -1
- metadata +3 -3
- data/lib/roda/project/templates/tests/minitest/spec/app/routes/foo_spec.rb +0 -8
- data/lib/roda/project/templates/tests/rspec/spec/app/routes/foo_spec.rb +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: beb637fce10cb01a9d71fbcceca4b10ccc6e04aa05bac094fc6327ed1854643e
|
|
4
|
+
data.tar.gz: 1ac1a13838ba8a5f5e6c65409e192ab9b15fe3f5ad9ee14dbc9d5b648a195434
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 471336f81ca6fd96226a001e599debeeb22302a284a78e8911a5bf0be02dd78c8010272b061f868d185ed82f3c943f84f6f90e2b35f44c807b2778027a24c019
|
|
7
|
+
data.tar.gz: 4ced8204c150d5208961c2315256151cd0eca3f2bd48905979684490450decc760f8d1b3828ac075fa1539d8e542ff4821cebfe0f70aa4df281efc0cc874e63a
|
|
@@ -12,9 +12,9 @@ class Roda
|
|
|
12
12
|
|
|
13
13
|
puts "* creating routes"
|
|
14
14
|
generate_routes
|
|
15
|
+
generate_nested_branch_files
|
|
15
16
|
generate_views
|
|
16
17
|
generate_tests
|
|
17
|
-
print_nested_branch_reminder
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
private
|
|
@@ -37,9 +37,8 @@ class Roda
|
|
|
37
37
|
hash_branch_header = if branch_name.include?("/")
|
|
38
38
|
parts = branch_name.split("/")
|
|
39
39
|
sub_path = parts[0..-2].join("/")
|
|
40
|
-
namespace = sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
41
40
|
branch_segment = parts.last
|
|
42
|
-
"hash_branch #{
|
|
41
|
+
"hash_branch #{namespace_for(sub_path)}, \"#{branch_segment}\" do |r|"
|
|
43
42
|
else
|
|
44
43
|
"hash_branch \"#{branch_name}\" do |r|"
|
|
45
44
|
end
|
|
@@ -85,8 +84,8 @@ class Roda
|
|
|
85
84
|
" expect(last_response.status).to eq(200)\n" \
|
|
86
85
|
" end"
|
|
87
86
|
else
|
|
88
|
-
" it \"responds to #{method.upcase} /#{branch_name} do\n" \
|
|
89
|
-
" #{method} \"/#{branch_name}\n" \
|
|
87
|
+
" it \"responds to #{method.upcase} /#{branch_name}\" do\n" \
|
|
88
|
+
" #{method} \"/#{branch_name}\"\n" \
|
|
90
89
|
" expect(last_response.status).to eq(200)\n" \
|
|
91
90
|
" end"
|
|
92
91
|
end
|
|
@@ -103,6 +102,57 @@ class Roda
|
|
|
103
102
|
action_success_message(test_filename)
|
|
104
103
|
end
|
|
105
104
|
|
|
105
|
+
def generate_nested_branch_files
|
|
106
|
+
return unless branch_name.include?("/")
|
|
107
|
+
|
|
108
|
+
parts = branch_name.split("/")
|
|
109
|
+
parts[0..-2].each_with_index do |_segment, index|
|
|
110
|
+
prefix = parts[0..index].join("/")
|
|
111
|
+
filename = File.join("app/routes", "#{prefix}.rb")
|
|
112
|
+
|
|
113
|
+
if File.exist?(filename)
|
|
114
|
+
ensure_hash_branches_line(filename, namespace_for(prefix))
|
|
115
|
+
next
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
dir = File.dirname(filename)
|
|
119
|
+
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
|
120
|
+
File.write(filename, nested_branch_file_content(prefix, index))
|
|
121
|
+
action_success_message(filename)
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def nested_branch_file_content(prefix, index)
|
|
126
|
+
parts = prefix.split("/")
|
|
127
|
+
segment = parts.last
|
|
128
|
+
header = if index.zero?
|
|
129
|
+
"hash_branch \"#{segment}\" do |r|"
|
|
130
|
+
else
|
|
131
|
+
parent_path = parts[0..-2].join("/")
|
|
132
|
+
"hash_branch #{namespace_for(parent_path)}, \"#{segment}\" do |r|"
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
<<~RUBY
|
|
136
|
+
class #{@context.const_project_name}
|
|
137
|
+
#{header} # #{prefix} branch
|
|
138
|
+
r.hash_branches(#{namespace_for(prefix)}) # #{prefix}/ +1 routes
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
RUBY
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def ensure_hash_branches_line(filename, namespace)
|
|
145
|
+
expected_line = "r.hash_branches(#{namespace})"
|
|
146
|
+
return if File.read(filename).include?(expected_line)
|
|
147
|
+
|
|
148
|
+
puts " warning: #{filename} already exists — please add:"
|
|
149
|
+
puts " #{expected_line}"
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def namespace_for(sub_path)
|
|
153
|
+
sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
154
|
+
end
|
|
155
|
+
|
|
106
156
|
def must_generate_views?
|
|
107
157
|
@options[:views] && Dir.exist?("app/views")
|
|
108
158
|
end
|
|
@@ -120,20 +170,6 @@ class Roda
|
|
|
120
170
|
def branch_name
|
|
121
171
|
@branch_name ||= @args[0]
|
|
122
172
|
end
|
|
123
|
-
|
|
124
|
-
def print_nested_branch_reminder
|
|
125
|
-
return unless branch_name.include?("/")
|
|
126
|
-
|
|
127
|
-
parts = branch_name.split("/")
|
|
128
|
-
sub_path = parts[0..-2].join("/")
|
|
129
|
-
namespace = sub_path.include?("/") ? ":\"#{sub_path}\"" : ":#{sub_path}"
|
|
130
|
-
|
|
131
|
-
puts "\ndont forget to add:\n\n" \
|
|
132
|
-
"autoload_hash_branch_dir(#{namespace}, \"./app/routes/#{sub_path}\")\n\n" \
|
|
133
|
-
"route do |r|\n" \
|
|
134
|
-
" r.on(\"#{sub_path}\") { r.hash_branches(#{namespace}) }\n" \
|
|
135
|
-
"end\n"
|
|
136
|
-
end
|
|
137
173
|
end
|
|
138
174
|
end
|
|
139
175
|
end
|
|
@@ -96,12 +96,10 @@ class Roda
|
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
def parse_args
|
|
99
|
-
@parse_args ||=
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{ type: "class", name: @args[0].to_s }
|
|
104
|
-
end
|
|
99
|
+
@parse_args ||= if %w[module class].include?(@args[0].to_s.downcase)
|
|
100
|
+
{type: @args[0].to_s.downcase, name: @args[1].to_s}
|
|
101
|
+
else
|
|
102
|
+
{type: "class", name: @args[0].to_s}
|
|
105
103
|
end
|
|
106
104
|
end
|
|
107
105
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
class <%= context.const_project_name %> < Roda
|
|
2
2
|
# Routing<% if context.fullstack? %>
|
|
3
|
-
plugin :
|
|
3
|
+
plugin :hash_branch_view_subdir<% end %>
|
|
4
4
|
plugin :autoload_hash_branches
|
|
5
|
-
autoload_hash_branch_dir(
|
|
5
|
+
HASH_BRANCHES.each { |args| autoload_hash_branch_dir(*args) }
|
|
6
|
+
|
|
6
7
|
plugin :all_verbs
|
|
7
8
|
plugin :not_found
|
|
8
9
|
<% if context.fullstack? %>
|
|
@@ -22,7 +22,6 @@ loader.collapse("#{__dir__}/app/models")<% end %>
|
|
|
22
22
|
# loader.push_dir("#{__dir__}/app/#{path}")
|
|
23
23
|
# end
|
|
24
24
|
loader.setup
|
|
25
|
-
require "debug" if Config.not_production?
|
|
26
25
|
|
|
27
26
|
Oj.mimic_JSON
|
|
28
27
|
|
|
@@ -32,10 +31,23 @@ Providers::Mailer.boot
|
|
|
32
31
|
Providers::Logger.boot
|
|
33
32
|
|
|
34
33
|
# Consts<% if context.database %>
|
|
35
|
-
DB = Providers::DB::Conn.get
|
|
34
|
+
DB = Providers::DB::Conn.get<% end %>
|
|
35
|
+
ROUTES_DIR = "./app/routes"
|
|
36
|
+
base_path = Pathname.new(ROUTES_DIR)
|
|
37
|
+
HASH_BRANCHES = []
|
|
38
|
+
HASH_BRANCHES << [base_path]
|
|
39
|
+
Dir.glob(File.join(ROUTES_DIR, "**/*")).each do |dir_path|
|
|
40
|
+
next unless File.directory?(dir_path)
|
|
41
|
+
|
|
42
|
+
path = Pathname.new(dir_path)
|
|
43
|
+
relative_path = path.relative_path_from(base_path).to_s
|
|
44
|
+
|
|
45
|
+
HASH_BRANCHES << [relative_path.to_sym, path.to_s]
|
|
46
|
+
end
|
|
36
47
|
|
|
37
|
-
# Automatic models annotations in dev environment
|
|
38
48
|
if Config.not_production?
|
|
49
|
+
require "debug"<% if context.database %>
|
|
50
|
+
# Automatic models annotations in dev environment
|
|
39
51
|
require 'sequel/annotate'
|
|
40
|
-
Sequel::Annotate.annotate(Dir['app/models/*.rb'], position: :before, border: true) rescue nil
|
|
41
|
-
end
|
|
52
|
+
Sequel::Annotate.annotate(Dir['app/models/*.rb'], position: :before, border: true) rescue nil<% end %>
|
|
53
|
+
end
|
|
@@ -2,13 +2,13 @@ require_relative "../spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "hello" do
|
|
4
4
|
it "test requests" do
|
|
5
|
-
get "/"
|
|
6
|
-
_(last_response.status).must_equal 302<% else %>
|
|
5
|
+
get "/"
|
|
7
6
|
_(last_response.status).must_equal 200<% if context.fullstack? %>
|
|
8
|
-
_(last_response.body).must_include "Hello world"<% end
|
|
7
|
+
_(last_response.body).must_include "Hello world"<% end %>
|
|
9
8
|
end
|
|
10
9
|
<% if context.rodauth? %>
|
|
11
10
|
it "test models" do
|
|
11
|
+
# run "RACK_ENV=test bin/roda db migrate" to make this spec pass
|
|
12
12
|
Account.create(email: "foo@bar.com")
|
|
13
13
|
|
|
14
14
|
_(Account.count).must_equal 1
|
|
@@ -2,12 +2,12 @@ require_relative "../spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe "hello" do
|
|
4
4
|
it "test requests" do
|
|
5
|
-
get "/"
|
|
6
|
-
expect(last_response.status).to eq(302)<% else %>
|
|
5
|
+
get "/"
|
|
7
6
|
expect(last_response.status).to eq(200)<% if context.fullstack? %>
|
|
8
|
-
expect(last_response.body).to include("Hello world")<% end
|
|
7
|
+
expect(last_response.body).to include("Hello world")<% end %>
|
|
9
8
|
end
|
|
10
9
|
<% if context.rodauth? %>
|
|
10
|
+
# run "RACK_ENV=test bin/roda db migrate" to make this spec pass
|
|
11
11
|
it "test models" do
|
|
12
12
|
Account.create(email: "foo@bar.com")
|
|
13
13
|
|
data/lib/roda/project/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.1.16
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Henrique F. Teixeira
|
|
@@ -142,12 +142,12 @@ files:
|
|
|
142
142
|
- lib/roda/project/templates/tests/minimal/rspec/spec/app_spec.rb
|
|
143
143
|
- lib/roda/project/templates/tests/minimal/rspec/spec/spec_helper.rb
|
|
144
144
|
- lib/roda/project/templates/tests/minitest/spec/app/app_spec.rb.erb
|
|
145
|
-
- lib/roda/project/templates/tests/minitest/spec/app/routes/foo_spec.rb
|
|
145
|
+
- lib/roda/project/templates/tests/minitest/spec/app/routes/foo_spec.rb.erb
|
|
146
146
|
- lib/roda/project/templates/tests/minitest/spec/app/routes/test_branch_spec.rb
|
|
147
147
|
- lib/roda/project/templates/tests/minitest/spec/app/views/html_spec.rb
|
|
148
148
|
- lib/roda/project/templates/tests/minitest/spec/spec_helper.rb.erb
|
|
149
149
|
- lib/roda/project/templates/tests/rspec/spec/app/app_spec.rb.erb
|
|
150
|
-
- lib/roda/project/templates/tests/rspec/spec/app/routes/foo_spec.rb
|
|
150
|
+
- lib/roda/project/templates/tests/rspec/spec/app/routes/foo_spec.rb.erb
|
|
151
151
|
- lib/roda/project/templates/tests/rspec/spec/app/routes/test_branch_spec.rb
|
|
152
152
|
- lib/roda/project/templates/tests/rspec/spec/app/views/html_spec.rb
|
|
153
153
|
- lib/roda/project/templates/tests/rspec/spec/spec_helper.rb.erb
|