jetski 0.2.8 → 0.3.0
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/jetski/base_controller.rb +21 -0
- data/lib/jetski/router.rb +98 -16
- data/lib/jetski/version.rb +1 -1
- data/lib/jetski.rb +1 -1
- data/templates/base/app/assets/images/jetski-logo.png +0 -0
- data/templates/base/app/controllers/pages_controller.rb +1 -0
- data/templates/base/app/views/layouts/application.html +1 -0
- metadata +2 -2
- data/templates/base/config/routes +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9d5b1bdf7d22ad076b4b10dd7c653521a2aa436779be86ccd3865121bed95d83
|
|
4
|
+
data.tar.gz: a7b4b87e4663ae80a462bd4b60ccad492a8e0276731e93352b9da2760c364042
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d670a9bef0b7ae5b81ab9e6bea1ed54a72a7c3bbec3fe4e30a575e9aaaabb056088e9c323bc48f2e57497f4420b8c8c6155db044c1e18f99325bbe68297df0fe
|
|
7
|
+
data.tar.gz: 517e89e18274819e70a5649a5da786aca96ef5f73c4fa87da400f4aade36f38e9cd3bf2e683a209efcfaf0d8850e0a79a7cb5b9dbdc2fe27f287d67472e6dd2c
|
|
@@ -3,13 +3,33 @@ module Jetski
|
|
|
3
3
|
class BaseController
|
|
4
4
|
attr_accessor :action_name, :controller_name
|
|
5
5
|
attr_reader :res
|
|
6
|
+
attr_reader :performed_render
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
def request_method(method)
|
|
10
|
+
# Really just a shell method since Im using File.readlines to use the logic in routes.
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def root
|
|
14
|
+
# another shell method
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def path(location)
|
|
18
|
+
# Another shell method
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
6
22
|
def initialize(res)
|
|
7
23
|
@res = res
|
|
24
|
+
@performed_render = false
|
|
8
25
|
end
|
|
9
26
|
|
|
10
27
|
# Method to render matching view with controller_name/action_name
|
|
11
28
|
|
|
12
29
|
def render(**args)
|
|
30
|
+
@performed_render = true
|
|
31
|
+
request_status = args[:status] || 200
|
|
32
|
+
res.status = request_status
|
|
13
33
|
if args[:text]
|
|
14
34
|
res.content_type = "text/plain"
|
|
15
35
|
res.body = "#{args[:text]}\n"
|
|
@@ -21,6 +41,7 @@ module Jetski
|
|
|
21
41
|
res.body = args[:json].to_json
|
|
22
42
|
return
|
|
23
43
|
end
|
|
44
|
+
|
|
24
45
|
render_template_file
|
|
25
46
|
end
|
|
26
47
|
|
data/lib/jetski/router.rb
CHANGED
|
@@ -10,38 +10,120 @@ module Jetski
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def parse_routes
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
auto_found_routes = []
|
|
14
|
+
controller_file_paths = Dir.glob([File.join(Jetski.app_root, 'app', 'controllers', '**', '*_controller.rb')])
|
|
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|
|
|
97
|
+
served_url = af_route[:url]
|
|
98
|
+
request_method = af_route[:method]
|
|
99
|
+
controller_classname = af_route[:controller_classname]
|
|
100
|
+
controller_name = af_route[:controller_name]
|
|
101
|
+
action_name = af_route[:action_name]
|
|
102
|
+
controller_file_name = af_route[:controller_file_name]
|
|
15
103
|
|
|
16
|
-
File.readlines(routes_file, chomp: true).each do |line|
|
|
17
|
-
route_action, served_url, controller_name, action_name = line.split(" ")
|
|
18
104
|
server.mount_proc served_url do |req, res|
|
|
19
105
|
errors = []
|
|
20
|
-
if (
|
|
106
|
+
if (request_method!= req.request_method)
|
|
21
107
|
errors << "Wrong request was performed"
|
|
22
108
|
end
|
|
23
|
-
# TODO: Fix the fact that we are always setting res.body to something here.
|
|
24
|
-
# Theres no way to return. We need to organize into case statement or if/else type
|
|
25
|
-
|
|
26
109
|
if errors.empty?
|
|
27
|
-
|
|
28
|
-
constantized_controller = "#{controller_name_formatted}Controller"
|
|
29
|
-
path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_name}_controller.rb")
|
|
110
|
+
path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_file_name}")
|
|
30
111
|
require_relative path_to_defined_controller
|
|
31
112
|
begin
|
|
32
|
-
controller_class = Object.const_get(
|
|
113
|
+
controller_class = Object.const_get(controller_classname)
|
|
33
114
|
rescue NameError
|
|
34
|
-
errors << "#{
|
|
115
|
+
errors << "#{controller_classname} is not defined. Please create a file app/controllers/#{controller_file_name}"
|
|
35
116
|
end
|
|
36
117
|
end
|
|
37
118
|
|
|
38
|
-
if errors.empty?
|
|
119
|
+
if errors.empty?
|
|
39
120
|
controller = controller_class.new(res)
|
|
40
121
|
controller.action_name = action_name
|
|
41
122
|
controller.controller_name = controller_name
|
|
42
123
|
controller.send(action_name)
|
|
43
|
-
|
|
44
|
-
|
|
124
|
+
if !controller.performed_render && (request_method.upcase == "GET")
|
|
125
|
+
controller.render
|
|
126
|
+
end
|
|
45
127
|
# TODO: Need to setup redirects for other request types. POST/PUT/DELETE
|
|
46
128
|
end
|
|
47
129
|
|
data/lib/jetski/version.rb
CHANGED
data/lib/jetski.rb
CHANGED
|
Binary file
|
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.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Indigo Tech Tutorials
|
|
@@ -52,11 +52,11 @@ files:
|
|
|
52
52
|
- lib/jetski/server.rb
|
|
53
53
|
- lib/jetski/version.rb
|
|
54
54
|
- templates/base/Gemfile
|
|
55
|
+
- templates/base/app/assets/images/jetski-logo.png
|
|
55
56
|
- templates/base/app/assets/stylesheets/application.css
|
|
56
57
|
- templates/base/app/controllers/pages_controller.rb
|
|
57
58
|
- templates/base/app/views/layouts/application.html
|
|
58
59
|
- templates/base/app/views/pages/home.html
|
|
59
|
-
- templates/base/config/routes
|
|
60
60
|
- templates/base/start.rb
|
|
61
61
|
homepage: https://rubygems.org/gems/jetski
|
|
62
62
|
licenses:
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
get / pages home
|