tora 0.0.2 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 198d46efb22fbaf5e5850a39e46f1cf529cd71deb80f694a84c5facd7deab608
4
- data.tar.gz: 5c663d60c574fe10b2e7ea4609acb6b4b6517a7f91e594fde5969e47e349e399
3
+ metadata.gz: 689ff41df26782feb0ba8e8f27b129316dd4979830e2f5a0783337f299942de2
4
+ data.tar.gz: 98236f2eaab79e2f0aea8bbbb986a40fd85aafa3d6b96b946b199040100e99db
5
5
  SHA512:
6
- metadata.gz: 49cd0771687af56c08981e1d092ab39fce7b0bfb70a6243254b57653accd6a381477457397c31931af90028db4b67882c2bf36c26ba1057057a40bfbfaf329f0
7
- data.tar.gz: 63be2280e8d6b324c316d66bf91f17a7ada94332a2cffdbc19a894ff9fd8310d7b1e0e7c56141bb01fef7155b26a855b90602df6d16db27caae886e4466be6b4
6
+ metadata.gz: 71ea136f1e91f3fa224e979d1b4e397b07998913dae07849501b9c2640718aeb548aa8238e2e1da031ca1e7a09c8c79383948a2b808517d9537817b7ef8b32b5
7
+ data.tar.gz: 4e71c3064cb9e4cdd0ba3895c75a718243c923fb7590782dd5648a0059fa0573e5b4a190e2da62cd1b60f21034a17cfe1760989421d5236aad3e51f94398d8a0
data/lib/array.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def deeply_empty?
3
+ empty? || all?(&:empty?)
4
+ end
5
+ end
@@ -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.2"
4
+ VERSION = "0.0.5"
5
5
  end
data/lib/tora.rb CHANGED
@@ -1,13 +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
- `echo debug > debug.log`
10
- [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]]
11
25
  end
12
26
  end
13
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.2
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - José Tapadas Alves
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack-test
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5'
27
55
  description: An opinionated rack-based ruby lightweight framework
28
56
  email:
29
57
  - jose@tapadas.dev
@@ -36,7 +64,11 @@ files:
36
64
  - LICENSE.txt
37
65
  - README.md
38
66
  - Rakefile
67
+ - lib/array.rb
39
68
  - lib/tora.rb
69
+ - lib/tora/controller.rb
70
+ - lib/tora/error_controller.rb
71
+ - lib/tora/routing.rb
40
72
  - lib/tora/version.rb
41
73
  - rebuild_gem.sh
42
74
  - sig/tora.rbs