jetski 0.2.5 → 0.2.6

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jetski/router.rb +26 -12
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1fd192f0597ad9af2b70dcad5b6b8b7247e3bd7959c349519f2ac4cfd0e1b422
4
- data.tar.gz: 8f5aeec13eeaf1468b6c7548d0f44de21ddf3cd30e58621d55655009e1872a39
3
+ metadata.gz: 831978e080c29ad5bfdf13d68c4eb578c008eb84e99316f3dd8209988399b582
4
+ data.tar.gz: 698027e9c51838c642f02871f77a09edcdabcb997e2e0688bc9a7abc9a8197aa
5
5
  SHA512:
6
- metadata.gz: b8e32a10022af778ae0af47b043a1b5efba2129df3cb37ee473e45de900721f1116fb4549e47c54458d38046a1e32997ebb9fb30d33dc5b5d55e715abddd2ea9
7
- data.tar.gz: 4c56bbc8de77e7bf2db76a602dfca4aaf71cf60850b8e5510a3f89fb4488eda2dcc72fd62c318232da92ec640d70f19f78401ffeda1363a36fe48dc3b6f081c3
6
+ metadata.gz: 83f11f888980010118f35a9717d666a3e85739ff425b0a3b76620d093a2a28a773b73edd04136de07462d678304362af5120365f751aa220b66e2d941a7ada89
7
+ data.tar.gz: 963765aee88f67fd4516853332cee01ef3e78558e99db439a31261078eb43f31b3ac8e5f61b6e65bfa50c393c296781fa6b2effdb035a9a6e019814af4755f78
data/lib/jetski/router.rb CHANGED
@@ -16,23 +16,35 @@ module Jetski
16
16
  File.readlines(routes_file, chomp: true).each do |line|
17
17
  route_action, served_url, controller_name, action_name = line.split(" ")
18
18
  server.mount_proc served_url do |req, res|
19
- constantized_controller = "#{controller_name.capitalize}Controller"
20
- path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_name}_controller.rb")
21
- require_relative path_to_defined_controller
22
- found_error = false
23
- begin
24
- controller_class = Object.const_get(constantized_controller)
25
- rescue NameError
26
- found_error = true
27
- # TODO: Move this into a method that can render a styled error to page.
28
- res.body = "#{constantized_controller} is not defined. Please create a file app/controllers/#{controller_name}.rb"
19
+ errors = []
20
+ if (route_action.upcase != req.request_method)
21
+ errors << "Wrong request was performed"
29
22
  end
30
- if found_error == false # Continue unless error found
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
+ if errors.empty?
27
+ constantized_controller = "#{controller_name.capitalize}Controller"
28
+ path_to_defined_controller = File.join(Jetski.app_root, "app/controllers/#{controller_name}_controller.rb")
29
+ require_relative path_to_defined_controller
30
+ begin
31
+ controller_class = Object.const_get(constantized_controller)
32
+ rescue NameError
33
+ errors << "#{constantized_controller} is not defined. Please create a file app/controllers/#{controller_name}.rb"
34
+ end
35
+ end
36
+
37
+ if errors.empty? # Continue unless error found
31
38
  controller = controller_class.new(res)
32
39
  controller.action_name = action_name
33
40
  controller.controller_name = controller_name
34
41
  controller.send(action_name)
35
- controller.render
42
+ # Render matching HTML template for GET requests only
43
+ controller.render if route_action.upcase == "GET"
44
+ end
45
+
46
+ if errors.any?
47
+ res.body = errors.join(", ")
36
48
  end
37
49
  end
38
50
  end
@@ -55,6 +67,8 @@ module Jetski
55
67
  end
56
68
 
57
69
  def host_images
70
+ # TODO: Expand this to support more types of images.
71
+
58
72
  image_files = Dir[
59
73
  File.join(Jetski.app_root, 'app/assets/images/*.jpg')
60
74
  ]
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.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Indigo Tech Tutorials