tora 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72f018a3b22b1a05410b91ee9b990d19d570e6b87a6edc4f97ef51941bd1fa7c
4
- data.tar.gz: 894762c243db721bdb221be640ac055262ad67334ceec4bfc631eba5ed3acdb3
3
+ metadata.gz: 689ff41df26782feb0ba8e8f27b129316dd4979830e2f5a0783337f299942de2
4
+ data.tar.gz: 98236f2eaab79e2f0aea8bbbb986a40fd85aafa3d6b96b946b199040100e99db
5
5
  SHA512:
6
- metadata.gz: 9309f90aae075562bc1ebd849dd91cdf7094d5c698a2eba385f0add3158d92b1ae1ddb5547e4f3f37aaddc585b5ba455eb0d3eaaf92238684239f97bff5a0461
7
- data.tar.gz: 35b4deebf65ff1e7e958b0c5c0967689e16dc6b175ab7211329793c17b26b85b8466ecce6fe8e888cd41afe1fcea2d9d5b40e173c268fec0139206bdcccaaf9b
6
+ metadata.gz: 71ea136f1e91f3fa224e979d1b4e397b07998913dae07849501b9c2640718aeb548aa8238e2e1da031ca1e7a09c8c79383948a2b808517d9537817b7ef8b32b5
7
+ data.tar.gz: 4e71c3064cb9e4cdd0ba3895c75a718243c923fb7590782dd5648a0059fa0573e5b4a190e2da62cd1b60f21034a17cfe1760989421d5236aad3e51f94398d8a0
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tora
4
+ class Controller
5
+ def initialize(env)
6
+ @env = env
7
+ end
8
+
9
+ def env
10
+ @env
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require "pp"
2
+
3
+ module Tora
4
+ class ErrorController < Tora::Controller
5
+ def error
6
+ "<h1>Tora Runtime Error</h1>" +
7
+ "<p>Here follows the insight:</p>" +
8
+ "<hr/>" +
9
+ "<div>" +
10
+ "<pre>#{@env.to_s.gsub('", ', '".<br>')}</pre>" +
11
+ "</div>" +
12
+ "<hr/>"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tora/controller"
4
+
5
+ module Tora
6
+ class Application
7
+ # this function will compose a magical name for the class of the component ant will try to instantiate
8
+ # the object that has that name and returns which action it should respond to. this is obtained via the
9
+ # part of the route we obtain
10
+ def get_controller_and_action(env)
11
+ _, controller_name, action, after = env["PATH_INFO"].split("/", 4)
12
+ controller_name = controller_name.capitalize + "Controller"
13
+
14
+ [Object.const_get(controller_name), action]
15
+ end
16
+ end
17
+ end
data/lib/tora/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tora
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.5"
5
5
  end
data/lib/tora.rb CHANGED
@@ -1,12 +1,27 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "tora/version"
3
+ require "tora/version"
4
+ require "tora/controller"
5
+ require "tora/routing"
6
+
7
+ # helper classes or modules
8
+ require "tora/error_controller"
4
9
 
5
10
  module Tora
6
11
  class Error < StandardError; end
12
+
7
13
  class Application
8
14
  def call(env)
9
- [200, { "Content-Type" => "text/html"}, ["Welcome to Tora!"]]
15
+ begin
16
+ controller_class, controller_action = get_controller_and_action(env)
17
+ controller = controller_class.new(env)
18
+ response = controller.send(controller_action)
19
+ rescue
20
+ controller = Tora::ErrorController.new(env)
21
+ response = controller.send('error')
22
+ end
23
+
24
+ [200, { "Content-Type" => "text/html"}, [response]]
10
25
  end
11
26
  end
12
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tora
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Tapadas Alves
@@ -66,6 +66,9 @@ files:
66
66
  - Rakefile
67
67
  - lib/array.rb
68
68
  - lib/tora.rb
69
+ - lib/tora/controller.rb
70
+ - lib/tora/error_controller.rb
71
+ - lib/tora/routing.rb
69
72
  - lib/tora/version.rb
70
73
  - rebuild_gem.sh
71
74
  - sig/tora.rbs