lennarb 1.4.0 → 1.5.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/.github/workflows/coverage.yaml +11 -33
- data/.github/workflows/documentation.yaml +32 -13
- data/.github/workflows/test.yaml +2 -1
- data/.gitignore +9 -0
- data/.yardopts +8 -0
- data/CODE_OF_CONDUCT.md +118 -0
- data/CONTRIBUTING.md +155 -0
- data/README.pt-BR.md +147 -0
- data/Rakefile +35 -2
- data/changelog.md +76 -0
- data/gems.rb +3 -22
- data/guides/getting-started/readme.md +48 -30
- data/guides/mounting-applications/readme.md +38 -0
- data/guides/response/readme.md +6 -6
- data/lennarb.gemspec +5 -2
- data/lib/lennarb/app.rb +253 -0
- data/lib/lennarb/base.rb +314 -0
- data/lib/lennarb/config.rb +52 -0
- data/lib/lennarb/constants.rb +12 -0
- data/lib/lennarb/environment.rb +80 -0
- data/lib/lennarb/errors.rb +17 -0
- data/lib/lennarb/helpers.rb +40 -0
- data/lib/lennarb/hooks.rb +71 -0
- data/lib/lennarb/logger.rb +100 -0
- data/lib/lennarb/middleware/request_logger.rb +117 -0
- data/lib/lennarb/middleware_stack.rb +56 -0
- data/lib/lennarb/parameter_filter.rb +76 -0
- data/lib/lennarb/request.rb +211 -33
- data/lib/lennarb/request_handler.rb +61 -0
- data/lib/lennarb/response.rb +34 -28
- data/lib/lennarb/route_node.rb +58 -4
- data/lib/lennarb/routes.rb +67 -0
- data/lib/lennarb/version.rb +2 -4
- data/lib/lennarb.rb +35 -67
- data/logo/lennarb.svg +11 -0
- data/readme.md +183 -34
- metadata +67 -7
- data/lib/lennarb/constansts.rb +0 -1
- data/logo/lennarb.png +0 -0
data/readme.md
CHANGED
@@ -1,65 +1,214 @@
|
|
1
1
|
<div align="center">
|
2
2
|
<picture>
|
3
|
-
<img alt="Lennarb" src="logo/lennarb.
|
3
|
+
<img alt="Lennarb" src="https://raw.githubusercontent.com/aristotelesbr/lennarb/refs/heads/main/logo/lennarb.svg" width="250">
|
4
4
|
</picture>
|
5
5
|
|
6
|
-
|
6
|
+
<hr>
|
7
|
+
|
8
|
+
<p>A lightweight, fast, and modular web framework for Ruby based on Rack. <strong>Lennarb</strong> supports Ruby (MRI) 3.4+</p>
|
9
|
+
|
10
|
+
<a href="https://github.com/aristotelesbr/lennarb/actions/workflows/test.yaml">
|
11
|
+
<img src="https://github.com/aristotelesbr/lennarb/actions/workflows/test.yaml/badge.svg" alt="Test">
|
12
|
+
</a>
|
13
|
+
<a href="https://rubygems.org/gems/lennarb">
|
14
|
+
<img src="https://img.shields.io/gem/v/lennarb.svg" alt="Gem">
|
15
|
+
</a>
|
16
|
+
<a href="https://rubygems.org/gems/lennarb">
|
17
|
+
<img src="https://img.shields.io/gem/dt/lennarb.svg" alt="Gem">
|
18
|
+
</a>
|
19
|
+
<a href="https://tldrlegal.com/license/mit-license">
|
20
|
+
<img src="https://img.shields.io/:License-MIT-blue.svg" alt="MIT License">
|
21
|
+
</a>
|
22
|
+
</div>
|
7
23
|
|
8
|
-
|
24
|
+
## Table of Contents
|
9
25
|
|
10
|
-
[
|
11
|
-
[
|
12
|
-
[
|
13
|
-
[
|
14
|
-
|
26
|
+
- [Features](#features)
|
27
|
+
- [Installation](#installation)
|
28
|
+
- [Quick Start](#quick-start)
|
29
|
+
- [Basic Usage](#basic-usage)
|
30
|
+
- [Documentation](#documentation)
|
31
|
+
- [Contributing](#contributing)
|
32
|
+
- [License](#license)
|
33
|
+
|
34
|
+
## Features
|
35
|
+
|
36
|
+
- Lightweight and modular architecture
|
37
|
+
- High-performance routing system
|
38
|
+
- Simple and intuitive API
|
39
|
+
- Support for middleware
|
40
|
+
- Flexible configuration options
|
41
|
+
- Two implementation options:
|
42
|
+
- `Lennarb::App`: Minimalist approach for single applications
|
43
|
+
- `Lennarb::Base`: Extended version for mounting multiple applications
|
44
|
+
|
45
|
+
## Installation
|
46
|
+
|
47
|
+
Add this line to your application's Gemfile:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
gem 'lennarb'
|
51
|
+
```
|
52
|
+
|
53
|
+
Or install it directly:
|
54
|
+
|
55
|
+
```bash
|
56
|
+
gem install lennarb
|
57
|
+
```
|
58
|
+
|
59
|
+
## Quick Start
|
60
|
+
|
61
|
+
Create a simple application with routes:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require "lennarb"
|
65
|
+
|
66
|
+
app = Lennarb::App.new do
|
67
|
+
routes do
|
68
|
+
get("/") do |req, res|
|
69
|
+
res.html("<h1>Welcome to Lennarb!</h1>")
|
70
|
+
end
|
71
|
+
|
72
|
+
get("/hello/:name") do |req, res|
|
73
|
+
name = req.params[:name]
|
74
|
+
res.html("Hello, #{name}!")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
app.initialize!
|
80
|
+
run app # In config.ru
|
81
|
+
```
|
82
|
+
|
83
|
+
Start with: `rackup`
|
15
84
|
|
16
85
|
## Basic Usage
|
17
86
|
|
87
|
+
### Creating a Simple Application
|
88
|
+
|
89
|
+
The `Lennarb::App` class is the core of the framework:
|
90
|
+
|
18
91
|
```ruby
|
19
92
|
require "lennarb"
|
20
93
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
94
|
+
class MyApp < Lennarb::App
|
95
|
+
# Define configuration
|
96
|
+
config do
|
97
|
+
mandatory :database_url, string
|
98
|
+
optional :port, int, 9292
|
99
|
+
end
|
100
|
+
|
101
|
+
# Define routes
|
102
|
+
routes do
|
103
|
+
get("/") do |req, res|
|
104
|
+
res.html("<h1>Welcome!</h1>")
|
105
|
+
end
|
106
|
+
|
107
|
+
post("/users") do |req, res|
|
108
|
+
# Access request data
|
109
|
+
data = req.body
|
110
|
+
res.json({status: "created", data: data})
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# Define hooks
|
115
|
+
before do |req, res|
|
116
|
+
# Run before every request
|
117
|
+
puts "Processing request: #{req.path}"
|
118
|
+
end
|
119
|
+
|
120
|
+
after do |req, res|
|
121
|
+
# Run after every request
|
122
|
+
puts "Completed request: #{req.path}"
|
123
|
+
end
|
124
|
+
|
125
|
+
# Define helper methods
|
126
|
+
helpers do
|
127
|
+
def format_date(date)
|
128
|
+
date.strftime("%Y-%m-%d")
|
129
|
+
end
|
25
130
|
end
|
26
131
|
end
|
132
|
+
|
133
|
+
run MyApp.new.initialize!
|
27
134
|
```
|
28
135
|
|
29
|
-
|
136
|
+
### Response Types
|
137
|
+
|
138
|
+
Lennarb provides various response methods:
|
30
139
|
|
31
|
-
|
140
|
+
```ruby
|
141
|
+
# HTML response
|
142
|
+
res.html("<h1>Hello World</h1>")
|
143
|
+
|
144
|
+
# JSON response
|
145
|
+
res.json({message: "Hello World"})
|
32
146
|
|
33
|
-
|
147
|
+
# Plain text response
|
148
|
+
res.text("Plain text response")
|
34
149
|
|
35
|
-
|
150
|
+
# Redirect
|
151
|
+
res.redirect("/new-location")
|
36
152
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
| 2 | Roda | 123.360,37 | 88.380,56 | 66.990,77 | 48.108,29 |
|
41
|
-
| 3 | Syro | 114.105,38 | 80.909,39 | 61.415,86 | 46.639,81 |
|
42
|
-
| 4 | Hanami-API | 68.089,18 | 52.851,88 | 40.801,78 | 27.996,00 |
|
153
|
+
# Custom status code
|
154
|
+
res.json({error: "Not found"}, status: 404)
|
155
|
+
```
|
43
156
|
|
44
|
-
|
157
|
+
### Mounting Applications
|
45
158
|
|
46
|
-
|
159
|
+
For larger applications, use `Lennarb::Base` to mount multiple apps:
|
47
160
|
|
48
|
-
|
161
|
+
```ruby
|
162
|
+
class API < Lennarb::App
|
163
|
+
routes do
|
164
|
+
get("/users") do |req, res|
|
165
|
+
res.json([{id: 1, name: "Alice"}, {id: 2, name: "Bob"}])
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class Admin < Lennarb::App
|
171
|
+
routes do
|
172
|
+
get("/dashboard") do |req, res|
|
173
|
+
res.html("<h1>Admin Dashboard</h1>")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
class Application < Lennarb::Base
|
179
|
+
# Add common middleware
|
180
|
+
middleware do
|
181
|
+
use Rack::Session::Cookie, secret: "your_secret"
|
182
|
+
end
|
183
|
+
|
184
|
+
# Mount applications at specific paths
|
185
|
+
mount(API, at: "/api")
|
186
|
+
mount(Admin, at: "/admin")
|
187
|
+
end
|
188
|
+
|
189
|
+
run Application.new.initialize!
|
190
|
+
```
|
49
191
|
|
50
|
-
|
192
|
+
## Documentation
|
51
193
|
|
52
|
-
|
194
|
+
For more detailed information, please see:
|
53
195
|
|
54
|
-
- [
|
196
|
+
- [Getting Started](https://aristotelesbr.github.io/lennarb/guides/getting-started/index) - Setup and first steps
|
197
|
+
- [Response](https://aristotelesbr.github.io/lennarb/guides/response/index.html) - Response handling
|
198
|
+
- [Request](https://aristotelesbr.github.io/lennarb/guides/request/index.html) - Request handling
|
199
|
+
- [Mounting Applications](https://aristotelesbr.github.io/lennarb/guides/mounting-applications/index.html) - Working with multiple apps
|
200
|
+
- [Performance](https://aristotelesbr.github.io/lennarb/guides/performance/index.html) - Benchmarks showing Lennarb's routing algorithm efficiency
|
55
201
|
|
56
|
-
|
57
|
-
The `res` object is used to send a response to the client. The Lennarb use a custom response object to send responses to the client. The `res` object is an instance of `Lennarb::Response`.
|
202
|
+
## Contributing
|
58
203
|
|
59
|
-
|
204
|
+
1. Fork the repository
|
205
|
+
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
206
|
+
3. Commit your changes (`git commit -am 'Add amazing feature'`)
|
207
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
208
|
+
5. Open a Pull Request
|
60
209
|
|
61
|
-
This project uses the [Developer Certificate of Origin](https://developercertificate.org/)
|
210
|
+
This project uses the [Developer Certificate of Origin](https://developercertificate.org/) and is governed by the [Contributor Covenant](https://www.contributor-covenant.org/).
|
62
211
|
|
63
|
-
|
212
|
+
## License
|
64
213
|
|
65
|
-
|
214
|
+
MIT License - see the [LICENSE](LICENSE) file for details.
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lennarb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aristóteles Coutinho
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-04-19 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bigdecimal
|
@@ -51,6 +51,34 @@ dependencies:
|
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '3.1'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: superconfig
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
61
|
+
type: :runtime
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: logger
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.7'
|
75
|
+
type: :runtime
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.7'
|
54
82
|
- !ruby/object:Gem::Dependency
|
55
83
|
name: bundler
|
56
84
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,7 +94,7 @@ dependencies:
|
|
66
94
|
- !ruby/object:Gem::Version
|
67
95
|
version: '0'
|
68
96
|
- !ruby/object:Gem::Dependency
|
69
|
-
name:
|
97
|
+
name: simplecov
|
70
98
|
requirement: !ruby/object:Gem::Requirement
|
71
99
|
requirements:
|
72
100
|
- - ">="
|
@@ -80,7 +108,7 @@ dependencies:
|
|
80
108
|
- !ruby/object:Gem::Version
|
81
109
|
version: '0'
|
82
110
|
- !ruby/object:Gem::Dependency
|
83
|
-
name: simplecov
|
111
|
+
name: simplecov-json
|
84
112
|
requirement: !ruby/object:Gem::Requirement
|
85
113
|
requirements:
|
86
114
|
- - ">="
|
@@ -107,6 +135,20 @@ dependencies:
|
|
107
135
|
- - ">="
|
108
136
|
- !ruby/object:Gem::Version
|
109
137
|
version: '0'
|
138
|
+
- !ruby/object:Gem::Dependency
|
139
|
+
name: minitest-utils
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
110
152
|
- !ruby/object:Gem::Dependency
|
111
153
|
name: rack-test
|
112
154
|
requirement: !ruby/object:Gem::Requirement
|
@@ -178,7 +220,7 @@ dependencies:
|
|
178
220
|
- !ruby/object:Gem::Version
|
179
221
|
version: '0'
|
180
222
|
- !ruby/object:Gem::Dependency
|
181
|
-
name:
|
223
|
+
name: debug
|
182
224
|
requirement: !ruby/object:Gem::Requirement
|
183
225
|
requirements:
|
184
226
|
- - ">="
|
@@ -206,7 +248,11 @@ files:
|
|
206
248
|
- ".gitignore"
|
207
249
|
- ".standard.yml"
|
208
250
|
- ".tool-versions"
|
251
|
+
- ".yardopts"
|
252
|
+
- CODE_OF_CONDUCT.md
|
253
|
+
- CONTRIBUTING.md
|
209
254
|
- LICENCE
|
255
|
+
- README.pt-BR.md
|
210
256
|
- Rakefile
|
211
257
|
- benchmark/memory.png
|
212
258
|
- benchmark/rps.png
|
@@ -219,17 +265,31 @@ files:
|
|
219
265
|
- gems.rb
|
220
266
|
- guides/getting-started/readme.md
|
221
267
|
- guides/links.yaml
|
268
|
+
- guides/mounting-applications/readme.md
|
222
269
|
- guides/performance/readme.md
|
223
270
|
- guides/response/readme.md
|
224
271
|
- lennarb.gemspec
|
225
272
|
- lib/lennarb.rb
|
226
|
-
- lib/lennarb/
|
273
|
+
- lib/lennarb/app.rb
|
274
|
+
- lib/lennarb/base.rb
|
275
|
+
- lib/lennarb/config.rb
|
276
|
+
- lib/lennarb/constants.rb
|
277
|
+
- lib/lennarb/environment.rb
|
278
|
+
- lib/lennarb/errors.rb
|
279
|
+
- lib/lennarb/helpers.rb
|
280
|
+
- lib/lennarb/hooks.rb
|
281
|
+
- lib/lennarb/logger.rb
|
282
|
+
- lib/lennarb/middleware/request_logger.rb
|
283
|
+
- lib/lennarb/middleware_stack.rb
|
284
|
+
- lib/lennarb/parameter_filter.rb
|
227
285
|
- lib/lennarb/request.rb
|
286
|
+
- lib/lennarb/request_handler.rb
|
228
287
|
- lib/lennarb/response.rb
|
229
288
|
- lib/lennarb/route_node.rb
|
289
|
+
- lib/lennarb/routes.rb
|
230
290
|
- lib/lennarb/version.rb
|
231
291
|
- license.md
|
232
|
-
- logo/lennarb.
|
292
|
+
- logo/lennarb.svg
|
233
293
|
- readme.md
|
234
294
|
homepage: https://aristotelesbr.github.io/lennarb
|
235
295
|
licenses:
|
data/lib/lennarb/constansts.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
HTTP_METHODS = %i[GET POST PUT PATCH DELETE HEAD OPTIONS].freeze
|
data/logo/lennarb.png
DELETED
Binary file
|