jetski 0.3.0 → 0.3.1
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/bin/jetski +9 -0
- data/lib/jetski/router/parser.rb +93 -0
- data/lib/jetski/router.rb +5 -86
- data/lib/jetski/version.rb +1 -1
- data/lib/jetski.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9695762a6c63b04e17d8477feff33bd1cf6e44a819a7112c17abed5c9411826b
|
|
4
|
+
data.tar.gz: 046a721b230e7fe80c5fe19a95a1a81d64d3e1956caff0163127a4752064a58a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3186f1f38ab5fd20ddbd24f6c3e9958f34e44161269333c83b1ae42208e64d4016ed03354458c4a7540c4e38784120a9ff8e971279465b2d66156d9909c0a7c3
|
|
7
|
+
data.tar.gz: 1b6674aaffba2a6054bd0d07e9923d5c0bf43df333572e4b81f9474c2d671d01c3ad63b987d0625a794012c227003b831c97ce3b956e7e3b655985f35677400c
|
data/bin/jetski
CHANGED
|
@@ -23,6 +23,15 @@ class JetskiCLI < Thor
|
|
|
23
23
|
say "Jetski v#{Jetski::VERSION}"
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
desc "routes", "shows the routes in your app."
|
|
27
|
+
def routes
|
|
28
|
+
compiled_routes = Jetski::Router::Parser.compile_routes
|
|
29
|
+
say "🌊 Jetski Routes 🏄♂️"
|
|
30
|
+
compiled_routes.each do |route_obj|
|
|
31
|
+
say "#{route_obj[:method]} #{route_obj[:url]} #{route_obj[:controller_name]}##{route_obj[:action_name]}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
26
35
|
def self.source_root
|
|
27
36
|
File.join(File.dirname(__FILE__), '..', 'templates')
|
|
28
37
|
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
module Jetski
|
|
2
|
+
class Router
|
|
3
|
+
module Parser
|
|
4
|
+
extend self
|
|
5
|
+
def compile_routes
|
|
6
|
+
auto_found_routes = []
|
|
7
|
+
controller_file_paths = Dir.glob([File.join(Jetski.app_root, 'app', 'controllers', '**', '*_controller.rb')])
|
|
8
|
+
controller_file_paths.each do |file_path|
|
|
9
|
+
controller_file_name = file_path.split('app/controllers')[1]
|
|
10
|
+
controller_as_url = controller_file_name.gsub(/_controller.rb/, '')
|
|
11
|
+
controller_name = controller_as_url.split("/").last
|
|
12
|
+
controller_classname = controller_as_url.split("/").reject(&:empty?).map(&:capitalize).join("::") + "Controller"
|
|
13
|
+
controller_file_readlines = File.readlines(file_path)
|
|
14
|
+
controller_file_readlines.each.with_index do |line, idx|
|
|
15
|
+
strp_line = line.strip
|
|
16
|
+
if strp_line.start_with?('def')
|
|
17
|
+
action_name = strp_line.split("def").last.strip
|
|
18
|
+
base_opts = {
|
|
19
|
+
controller_classname: controller_classname,
|
|
20
|
+
controller_file_name: controller_file_name,
|
|
21
|
+
controller_name: controller_name
|
|
22
|
+
}
|
|
23
|
+
case action_name
|
|
24
|
+
when "new"
|
|
25
|
+
auto_found_routes << base_opts.merge({
|
|
26
|
+
url: controller_as_url + "/new",
|
|
27
|
+
method: "GET",
|
|
28
|
+
action_name: action_name,
|
|
29
|
+
})
|
|
30
|
+
when "create"
|
|
31
|
+
auto_found_routes << base_opts.merge({
|
|
32
|
+
url: controller_as_url,
|
|
33
|
+
method: "POST",
|
|
34
|
+
action_name: action_name,
|
|
35
|
+
})
|
|
36
|
+
when "show"
|
|
37
|
+
auto_found_routes << base_opts.merge({
|
|
38
|
+
url: controller_as_url + "/:id",
|
|
39
|
+
method: "GET",
|
|
40
|
+
action_name: action_name,
|
|
41
|
+
})
|
|
42
|
+
when "edit"
|
|
43
|
+
auto_found_routes << base_opts.merge({
|
|
44
|
+
url: controller_as_url + "/:id/edit",
|
|
45
|
+
method: "GET",
|
|
46
|
+
action_name: action_name,
|
|
47
|
+
})
|
|
48
|
+
when "update"
|
|
49
|
+
auto_found_routes << base_opts.merge({
|
|
50
|
+
url: controller_as_url + "/:id",
|
|
51
|
+
method: "PUT",
|
|
52
|
+
action_name: action_name,
|
|
53
|
+
})
|
|
54
|
+
when "destroy"
|
|
55
|
+
auto_found_routes << base_opts.merge({
|
|
56
|
+
url: controller_as_url + "/:id",
|
|
57
|
+
method: "DELETE",
|
|
58
|
+
action_name: action_name,
|
|
59
|
+
})
|
|
60
|
+
else
|
|
61
|
+
method_route_options = controller_file_readlines[(idx - 2)..(idx - 1)].map(&:strip)
|
|
62
|
+
custom_request_method = method_route_options.find { |line| line.start_with? "request_method" }
|
|
63
|
+
custom_request_method = if custom_request_method
|
|
64
|
+
custom_request_method.split(" ")[1].gsub('"', '').upcase
|
|
65
|
+
else
|
|
66
|
+
"GET"
|
|
67
|
+
end
|
|
68
|
+
custom_path_option = method_route_options.find { |line| line.start_with? "path" }
|
|
69
|
+
check_root = controller_file_readlines[idx - 1].strip
|
|
70
|
+
url_to_use = if check_root.include?("root")
|
|
71
|
+
"/"
|
|
72
|
+
else
|
|
73
|
+
if custom_path_option
|
|
74
|
+
custom_path_option.split(" ")[1].gsub('"', '')
|
|
75
|
+
else
|
|
76
|
+
url_friendly_action_name = action_name.split("_").join("-")
|
|
77
|
+
controller_as_url + "/#{url_friendly_action_name}"
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
auto_found_routes << base_opts.merge({
|
|
81
|
+
url: url_to_use,
|
|
82
|
+
method: custom_request_method,
|
|
83
|
+
action_name: action_name,
|
|
84
|
+
})
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
auto_found_routes
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
data/lib/jetski/router.rb
CHANGED
|
@@ -1,99 +1,18 @@
|
|
|
1
1
|
module Jetski
|
|
2
2
|
class Router
|
|
3
|
+
include Parser
|
|
3
4
|
attr_reader :server
|
|
4
5
|
def initialize(server)
|
|
5
6
|
@server = server
|
|
6
7
|
end
|
|
7
8
|
|
|
8
9
|
def call
|
|
9
|
-
|
|
10
|
+
host_routes && host_assets
|
|
10
11
|
end
|
|
11
12
|
|
|
12
|
-
def
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
controller_file_paths.each do |file_path|
|
|
16
|
-
controller_file_name = file_path.split('app/controllers')[1]
|
|
17
|
-
controller_as_url = controller_file_name.gsub(/_controller.rb/, '')
|
|
18
|
-
controller_name = controller_as_url.split("/").last
|
|
19
|
-
controller_classname = controller_as_url.split("/").reject(&:empty?).map(&:capitalize).join("::") + "Controller"
|
|
20
|
-
controller_file_readlines = File.readlines(file_path)
|
|
21
|
-
controller_file_readlines.each.with_index do |line, idx|
|
|
22
|
-
strp_line = line.strip
|
|
23
|
-
if strp_line.start_with?('def')
|
|
24
|
-
action_name = strp_line.split("def").last.strip
|
|
25
|
-
base_opts = {
|
|
26
|
-
controller_classname: controller_classname,
|
|
27
|
-
controller_file_name: controller_file_name,
|
|
28
|
-
controller_name: controller_name
|
|
29
|
-
}
|
|
30
|
-
case action_name
|
|
31
|
-
when "new"
|
|
32
|
-
auto_found_routes << base_opts.merge({
|
|
33
|
-
url: controller_as_url + "/new",
|
|
34
|
-
method: "GET",
|
|
35
|
-
action_name: action_name,
|
|
36
|
-
})
|
|
37
|
-
when "create"
|
|
38
|
-
auto_found_routes << base_opts.merge({
|
|
39
|
-
url: controller_as_url,
|
|
40
|
-
method: "POST",
|
|
41
|
-
action_name: action_name,
|
|
42
|
-
})
|
|
43
|
-
when "show"
|
|
44
|
-
auto_found_routes << base_opts.merge({
|
|
45
|
-
url: controller_as_url + "/:id",
|
|
46
|
-
method: "GET",
|
|
47
|
-
action_name: action_name,
|
|
48
|
-
})
|
|
49
|
-
when "edit"
|
|
50
|
-
auto_found_routes << base_opts.merge({
|
|
51
|
-
url: controller_as_url + "/:id/edit",
|
|
52
|
-
method: "GET",
|
|
53
|
-
action_name: action_name,
|
|
54
|
-
})
|
|
55
|
-
when "update"
|
|
56
|
-
auto_found_routes << base_opts.merge({
|
|
57
|
-
url: controller_as_url + "/:id",
|
|
58
|
-
method: "PUT",
|
|
59
|
-
action_name: action_name,
|
|
60
|
-
})
|
|
61
|
-
when "destroy"
|
|
62
|
-
auto_found_routes << base_opts.merge({
|
|
63
|
-
url: controller_as_url + "/:id",
|
|
64
|
-
method: "DELETE",
|
|
65
|
-
action_name: action_name,
|
|
66
|
-
})
|
|
67
|
-
else
|
|
68
|
-
method_route_options = controller_file_readlines[(idx - 2)..(idx - 1)].map(&:strip)
|
|
69
|
-
custom_request_method = method_route_options.find { |line| line.start_with? "request_method" }
|
|
70
|
-
custom_request_method = if custom_request_method
|
|
71
|
-
custom_request_method.split(" ")[1].gsub('"', '').upcase
|
|
72
|
-
else
|
|
73
|
-
"GET"
|
|
74
|
-
end
|
|
75
|
-
custom_path_option = method_route_options.find { |line| line.start_with? "path" }
|
|
76
|
-
check_root = controller_file_readlines[idx - 1].strip
|
|
77
|
-
url_to_use = if check_root.include?("root")
|
|
78
|
-
"/"
|
|
79
|
-
else
|
|
80
|
-
if custom_path_option
|
|
81
|
-
custom_path_option.split(" ")[1].gsub('"', '')
|
|
82
|
-
else
|
|
83
|
-
controller_as_url + "/#{action_name}"
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
auto_found_routes << base_opts.merge({
|
|
87
|
-
url: url_to_use,
|
|
88
|
-
method: custom_request_method,
|
|
89
|
-
action_name: action_name,
|
|
90
|
-
})
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
auto_found_routes.each do |af_route|
|
|
13
|
+
def host_routes
|
|
14
|
+
routes = compile_routes
|
|
15
|
+
routes.each do |af_route|
|
|
97
16
|
served_url = af_route[:url]
|
|
98
17
|
request_method = af_route[:method]
|
|
99
18
|
controller_classname = af_route[:controller_classname]
|
data/lib/jetski/version.rb
CHANGED
data/lib/jetski.rb
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
require_relative './jetski/version'
|
|
2
2
|
require_relative './jetski/base_controller'
|
|
3
3
|
require_relative './jetski/server'
|
|
4
|
+
require_relative './jetski/router/parser'
|
|
4
5
|
require_relative './jetski/router'
|
|
5
6
|
require "webrick"
|
|
6
7
|
require "json"
|
|
8
|
+
require "json"
|
|
7
9
|
|
|
8
10
|
module Jetski
|
|
9
11
|
# Debug stage add constants here for debugging.
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: jetski
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Indigo Tech Tutorials
|
|
@@ -49,6 +49,7 @@ files:
|
|
|
49
49
|
- lib/jetski.rb
|
|
50
50
|
- lib/jetski/base_controller.rb
|
|
51
51
|
- lib/jetski/router.rb
|
|
52
|
+
- lib/jetski/router/parser.rb
|
|
52
53
|
- lib/jetski/server.rb
|
|
53
54
|
- lib/jetski/version.rb
|
|
54
55
|
- templates/base/Gemfile
|