lennarb 1.1.0 → 1.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 +4 -4
- data/lib/lennarb/application/base.rb +35 -5
- data/lib/lennarb/route_node.rb +12 -0
- data/lib/lennarb/version.rb +1 -1
- data/lib/lennarb.rb +12 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd399f9aecbae5c09d1928317826fd82c62207a36d76ad6a1591a7757811d6e4
|
4
|
+
data.tar.gz: 3f1ecf28399eeb28a8d739e50ffc01ecd0ae7328057c4132f15e6a12b65cd1e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b32f1d120bfd85de2512721631c90e95aa32622dfd69e41e90ce66f7d61b22db235b30c5de8329bfd1669dc4ca9b880bcb858068246362422e0c0b545b1e29af
|
7
|
+
data.tar.gz: 28e13690c911ddb81d97c9e4fab95c270eb7e0367d2a26ea89b959252b3a449d611cb9dc067d0428e8959aa2beb96a9e9f3240462c97fbe480aecfd47ae169fd
|
@@ -32,9 +32,10 @@ class Lennarb
|
|
32
32
|
#
|
33
33
|
# @returns [Base]
|
34
34
|
#
|
35
|
-
|
36
35
|
class << self
|
37
36
|
def inherited(subclass)
|
37
|
+
super
|
38
|
+
_applications << subclass
|
38
39
|
subclass.instance_variable_set(:@_route, Lennarb.new)
|
39
40
|
subclass.instance_variable_set(:@_middlewares, [])
|
40
41
|
subclass.instance_variable_set(:@_global_after_hooks, [])
|
@@ -51,9 +52,23 @@ class Lennarb
|
|
51
52
|
def patch(...) = @_route.patch(...)
|
52
53
|
def delete(...) = @_route.delete(...)
|
53
54
|
def options(...) = @_route.options(...)
|
54
|
-
|
55
|
+
|
55
56
|
# @returns [Array] middlewares
|
56
|
-
|
57
|
+
#
|
58
|
+
def _middlewares = @_middlewares ||= []
|
59
|
+
|
60
|
+
# @returns [Array] applications
|
61
|
+
#
|
62
|
+
def _applications = @_applications ||= []
|
63
|
+
|
64
|
+
# Mount a controller
|
65
|
+
#
|
66
|
+
# @parameter [Class] controller
|
67
|
+
#
|
68
|
+
def mount(controller_class)
|
69
|
+
_applications << controller_class
|
70
|
+
puts "Mounted controller: #{controller_class}"
|
71
|
+
end
|
57
72
|
|
58
73
|
# Use a middleware
|
59
74
|
#
|
@@ -117,10 +132,26 @@ class Lennarb
|
|
117
132
|
use Rack::Head
|
118
133
|
use Rack::ContentLength
|
119
134
|
|
120
|
-
|
135
|
+
_middlewares.each do |(middleware, args, block)|
|
121
136
|
stack.use(middleware, *args, &block)
|
122
137
|
end
|
123
138
|
|
139
|
+
_applications.each do |app|
|
140
|
+
app_route = app.instance_variable_get(:@_route)
|
141
|
+
|
142
|
+
app_after_hooks = app.instance_variable_get(:@_after_hooks)
|
143
|
+
app_before_hooks = app.instance_variable_get(:@_before_hooks)
|
144
|
+
global_after_hooks = app.instance_variable_get(:@_global_after_hooks)
|
145
|
+
global_before_hooks = app.instance_variable_get(:@_global_before_hooks)
|
146
|
+
|
147
|
+
@_route.merge!(app_route)
|
148
|
+
@_before_hooks.merge!(app_before_hooks)
|
149
|
+
@_after_hooks.merge!(app_after_hooks)
|
150
|
+
|
151
|
+
@_global_before_hooks.concat(global_before_hooks)
|
152
|
+
@_global_after_hooks.concat(global_after_hooks)
|
153
|
+
end
|
154
|
+
|
124
155
|
stack.run ->(env) do
|
125
156
|
catch(:halt) do
|
126
157
|
execute_hooks(@_before_hooks, env, :before)
|
@@ -137,7 +168,6 @@ class Lennarb
|
|
137
168
|
end
|
138
169
|
|
139
170
|
@_route.freeze!
|
140
|
-
|
141
171
|
stack.to_app
|
142
172
|
end
|
143
173
|
|
data/lib/lennarb/route_node.rb
CHANGED
@@ -68,5 +68,17 @@ class Lennarb
|
|
68
68
|
|
69
69
|
[nil, nil]
|
70
70
|
end
|
71
|
+
|
72
|
+
# Merge the other RouteNode into the current one
|
73
|
+
#
|
74
|
+
# @parameter other [RouteNode] The other RouteNode to merge into the current one
|
75
|
+
#
|
76
|
+
# @return [void]
|
77
|
+
#
|
78
|
+
def merge!(other)
|
79
|
+
self.static_children.merge!(other.static_children)
|
80
|
+
self.dynamic_children.merge!(other.dynamic_children)
|
81
|
+
self.blocks.merge!(other.blocks)
|
82
|
+
end
|
71
83
|
end
|
72
84
|
end
|
data/lib/lennarb/version.rb
CHANGED
data/lib/lennarb.rb
CHANGED
@@ -115,6 +115,18 @@ class Lennarb
|
|
115
115
|
@_applied_plugins << plugin_name
|
116
116
|
end
|
117
117
|
|
118
|
+
# Merge the other RouteNode into the current one
|
119
|
+
#
|
120
|
+
# @parameter other [RouteNode] The other RouteNode to merge into the current one
|
121
|
+
#
|
122
|
+
# @return [void]
|
123
|
+
#
|
124
|
+
def merge!(other)
|
125
|
+
raise "Expected a Lennarb instance, got #{other.class}" unless other.is_a?(Lennarb)
|
126
|
+
|
127
|
+
@_root.merge!(other._root)
|
128
|
+
end
|
129
|
+
|
118
130
|
private
|
119
131
|
|
120
132
|
# Add a route
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lennarb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aristóteles Coutinho
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|