rackstep 0.0.7 → 0.2.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 +5 -5
- data/lib/rackstep.rb +8 -12
- data/lib/response.rb +1 -7
- data/lib/route.rb +16 -16
- data/lib/router.rb +0 -2
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 81edfdbc71dc5bedd6439a6ce865c7aab97a02ae5f9c9c670ae9c5437dca104b
|
|
4
|
+
data.tar.gz: 3e2c8a5bd702f9d35b6aae7386ef68d30bd316ac7cbaf0b9f62ea556bc2c80c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77cb6a2eed06b75ba409c418951f6736e550bcd403fa7cc4c24a7f57932e384a36f41277d703e5f54c9c10b3532e79af50af8435bbed5af983393cf27c9dfd75
|
|
7
|
+
data.tar.gz: f70caba2a772821ad8c021944ef15bc35330513e0ddf1706df24ce78794ce51201f38b6badb49401ac9e5c6db91266f530cffffc6fe03e28afb3b26fc9f39bdb
|
data/lib/rackstep.rb
CHANGED
|
@@ -10,9 +10,10 @@ require_relative 'route'
|
|
|
10
10
|
require_relative 'router'
|
|
11
11
|
require_relative 'controller'
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
module RackStep
|
|
14
15
|
|
|
15
|
-
# Abstract class with the base of a RackStep app.
|
|
16
|
+
# Abstract class with the base of a RackStep app.
|
|
16
17
|
# This class MUST be extended by the user.
|
|
17
18
|
class App
|
|
18
19
|
|
|
@@ -26,7 +27,8 @@ module RackStep
|
|
|
26
27
|
|
|
27
28
|
# Static method called from config.ru ("run App").
|
|
28
29
|
def self.call(env)
|
|
29
|
-
new(env).process_request
|
|
30
|
+
response = new(env).process_request
|
|
31
|
+
return response.status, response.headers, response.body
|
|
30
32
|
end
|
|
31
33
|
|
|
32
34
|
# Initialize the request instance variable and add a default "not found" route.
|
|
@@ -34,7 +36,7 @@ module RackStep
|
|
|
34
36
|
@request = Rack::Request.new(env)
|
|
35
37
|
|
|
36
38
|
# Adding default routes to handle page not found (404).
|
|
37
|
-
router.add_route_for_all_verbs('notfound',
|
|
39
|
+
router.add_route_for_all_verbs('notfound', RackStep::NotFoundController)
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
# TODO: Code Climate says this method is too big.
|
|
@@ -42,27 +44,21 @@ module RackStep
|
|
|
42
44
|
verb = request.request_method
|
|
43
45
|
path = request.path
|
|
44
46
|
|
|
45
|
-
# In RackStep, each request is processed by a controller. The router
|
|
47
|
+
# In RackStep, each request is processed by a controller. The router
|
|
46
48
|
# is responsable to find, based on the given path and http verb,
|
|
47
49
|
# the apropriate controller to handle the request.
|
|
48
50
|
route = router.find_route_for(path, verb)
|
|
49
|
-
|
|
50
|
-
controller = Object.const_get(route.controller).new
|
|
51
|
-
# Inject the request into the controller.
|
|
51
|
+
controller = route.controller.new
|
|
52
52
|
controller.request = request
|
|
53
|
-
# Execute the before method of this controller.
|
|
54
53
|
controller.send(:before)
|
|
55
|
-
# Execute the apropriate method/action.
|
|
56
54
|
controller.send(:process_request)
|
|
57
|
-
# Execute the after method of this controller.
|
|
58
55
|
controller.send(:after)
|
|
59
|
-
# Get from the controller what is the response for this request.
|
|
60
56
|
response = controller.response
|
|
61
57
|
|
|
62
58
|
return response
|
|
63
59
|
end
|
|
64
60
|
|
|
65
|
-
# This method was created to make it easier for the user to add routes, but it
|
|
61
|
+
# This method was created to make it easier for the user to add routes, but it
|
|
66
62
|
# will delegate to the router singleton class.
|
|
67
63
|
def self.add_route(verb, path, controller)
|
|
68
64
|
router = Router.instance
|
data/lib/response.rb
CHANGED
|
@@ -10,25 +10,19 @@ module RackStep
|
|
|
10
10
|
# necessary.
|
|
11
11
|
def body=(value)
|
|
12
12
|
if value.is_a?(String)
|
|
13
|
-
# Convert it to an array.
|
|
14
13
|
value = [value]
|
|
15
14
|
end
|
|
16
15
|
|
|
17
16
|
super(value)
|
|
18
17
|
end
|
|
19
18
|
|
|
20
|
-
#
|
|
19
|
+
# Helpers
|
|
21
20
|
def content_type
|
|
22
21
|
header['Content-Type']
|
|
23
22
|
end
|
|
24
|
-
|
|
25
|
-
# Just a helper to set the content type on the response header.
|
|
26
23
|
def content_type=(value)
|
|
27
24
|
header['Content-Type'] = value
|
|
28
25
|
end
|
|
29
|
-
|
|
30
|
-
# A helper for redirecting to another adddress.
|
|
31
|
-
# Will send back a 302 status code.
|
|
32
26
|
def redirect_to(address)
|
|
33
27
|
@status = 302
|
|
34
28
|
header['Location'] = address
|
data/lib/route.rb
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Represents a single route. The verb can be 'GET', 'PUT', 'POST' or 'DELETE'.
|
|
2
|
+
# The path is a string with something like 'users', the controller is the
|
|
3
|
+
# name of the class that will process this type of request.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
module RackStep
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
class Route
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
attr_accessor :verb, :path, :controller
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
# Unique id (String) of the route (verb + path). Eg: 'GETuser'.
|
|
18
|
-
def id
|
|
19
|
-
verb + path
|
|
20
|
-
end
|
|
11
|
+
def initialize(verb, path, controller)
|
|
12
|
+
@verb = verb
|
|
13
|
+
@path = path
|
|
14
|
+
@controller = controller
|
|
15
|
+
end
|
|
21
16
|
|
|
17
|
+
# Unique id (String) of the route (verb + path). Eg: 'GETuser'.
|
|
18
|
+
def id
|
|
19
|
+
verb + path
|
|
22
20
|
end
|
|
23
21
|
|
|
22
|
+
end
|
|
23
|
+
|
|
24
24
|
end
|
data/lib/router.rb
CHANGED
|
@@ -32,9 +32,7 @@ module RackStep
|
|
|
32
32
|
# 'http//localhost/' will be the same of 'http://localhost' (both will
|
|
33
33
|
# be empty strings).
|
|
34
34
|
path = path[1..-1] if path[0] == '/'
|
|
35
|
-
# Re-creating the route id (verb + path).
|
|
36
35
|
route_id = verb + path
|
|
37
|
-
# Getting the correspondent route or nil if route is invalid.
|
|
38
36
|
route = routes[route_id]
|
|
39
37
|
# If no route was found, set it to 'notfound' route (maintaining the
|
|
40
38
|
# original verb).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rackstep
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Marcio Frayze David
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-06-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: RackStep is (yet another) micro ruby framework for microservices and
|
|
14
14
|
web development.
|
|
@@ -26,7 +26,7 @@ homepage: https://github.com/mfdavid/rackstep
|
|
|
26
26
|
licenses:
|
|
27
27
|
- MIT
|
|
28
28
|
metadata: {}
|
|
29
|
-
post_install_message:
|
|
29
|
+
post_install_message:
|
|
30
30
|
rdoc_options: []
|
|
31
31
|
require_paths:
|
|
32
32
|
- lib
|
|
@@ -41,9 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
41
41
|
- !ruby/object:Gem::Version
|
|
42
42
|
version: '0'
|
|
43
43
|
requirements: []
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
signing_key:
|
|
44
|
+
rubygems_version: 3.2.15
|
|
45
|
+
signing_key:
|
|
47
46
|
specification_version: 4
|
|
48
47
|
summary: RackStep micro web framework
|
|
49
48
|
test_files: []
|