lennarb 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
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: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aristóteles Coutinho
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-25 00:00:00.000000000 Z
11
+ date: 2023-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.1'
27
- - !ruby/object:Gem::Dependency
28
- name: puma
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '6.4'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '6.4'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rack
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,77 +45,97 @@ dependencies:
59
45
  - !ruby/object:Gem::Version
60
46
  version: 3.0.8
61
47
  - !ruby/object:Gem::Dependency
62
- name: rake
48
+ name: bake
63
49
  requirement: !ruby/object:Gem::Requirement
64
50
  requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '13.0'
68
51
  - - ">="
69
52
  - !ruby/object:Gem::Version
70
- version: 13.0.6
71
- type: :runtime
53
+ version: 0.18.2
54
+ type: :development
72
55
  prerelease: false
73
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.18.2
61
+ - !ruby/object:Gem::Dependency
62
+ name: covered
63
+ requirement: !ruby/object:Gem::Requirement
74
64
  requirements:
75
65
  - - "~>"
76
66
  - !ruby/object:Gem::Version
77
- version: '13.0'
78
- - - ">="
67
+ version: 0.25.1
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
79
73
  - !ruby/object:Gem::Version
80
- version: 13.0.6
74
+ version: 0.25.1
81
75
  - !ruby/object:Gem::Dependency
82
- name: minitest
76
+ name: puma
83
77
  requirement: !ruby/object:Gem::Requirement
84
78
  requirements:
85
79
  - - "~>"
86
80
  - !ruby/object:Gem::Version
87
- version: '5.20'
81
+ version: '6.4'
88
82
  type: :development
89
83
  prerelease: false
90
84
  version_requirements: !ruby/object:Gem::Requirement
91
85
  requirements:
92
86
  - - "~>"
93
87
  - !ruby/object:Gem::Version
94
- version: '5.20'
88
+ version: '6.4'
95
89
  - !ruby/object:Gem::Dependency
96
- name: rake
90
+ name: rack-test
97
91
  requirement: !ruby/object:Gem::Requirement
98
92
  requirements:
99
93
  - - "~>"
100
94
  - !ruby/object:Gem::Version
101
- version: '13.0'
102
- - - ">="
95
+ version: '2.1'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.1'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
103
108
  - !ruby/object:Gem::Version
104
- version: 13.0.6
109
+ version: '1.59'
105
110
  type: :development
106
111
  prerelease: false
107
112
  version_requirements: !ruby/object:Gem::Requirement
108
113
  requirements:
109
114
  - - "~>"
110
115
  - !ruby/object:Gem::Version
111
- version: '13.0'
112
- - - ">="
116
+ version: '1.59'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-minitest
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.33.0
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
113
129
  - !ruby/object:Gem::Version
114
- version: 13.0.6
115
- description: 'Lenna is a lightweight and experimental web framework for Ruby. It''s
116
- designed to be modular and easy to use. Also, that''s how I affectionately call
117
- my wife.
118
-
119
- '
130
+ version: 0.33.0
131
+ description:
120
132
  email:
121
- - aristotelesbr@gmail.com
122
133
  executables: []
123
134
  extensions: []
124
- extra_rdoc_files:
125
- - README.md
126
- - LICENCE
127
- - CHANGELOG.md
135
+ extra_rdoc_files: []
128
136
  files:
129
- - CHANGELOG.md
130
- - LICENCE
131
- - README.md
132
- - lib/lenna/base.rb
137
+ - changelog.md
138
+ - lib/lenna/application.rb
133
139
  - lib/lenna/middleware/app.rb
134
140
  - lib/lenna/middleware/default/error_handler.rb
135
141
  - lib/lenna/middleware/default/logging.rb
@@ -143,15 +149,17 @@ files:
143
149
  - lib/lennarb.rb
144
150
  - lib/lennarb/array_extensions.rb
145
151
  - lib/lennarb/version.rb
146
- homepage: https://rubygems.org/gems/lennarb
152
+ - license.md
153
+ - readme.md
154
+ homepage: https://aristotelesbr.github.io/lennarb
147
155
  licenses:
148
156
  - MIT
149
157
  metadata:
150
158
  allowed_push_host: https://rubygems.org/gems/lennarb
151
- homepage_uri: https://rubygems.org/gems/lennarb
152
- source_code_uri: https://github.com/aristotelesbr/lennarb
153
- changelog_uri: https://github.com/aristotelesbr/lennarb/blob/master/CHANGELOG.md
159
+ changelog_uri: https://github.com/aristotelesbr/lennarb/blob/master/changelog.md
160
+ homepage_uri: https://aristotelesbr.github.io/lennarb
154
161
  rubygems_mfa_required: 'true'
162
+ source_code_uri: https://github.com/aristotelesbr/lennarb
155
163
  post_install_message:
156
164
  rdoc_options: []
157
165
  require_paths:
@@ -160,14 +168,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
168
  requirements:
161
169
  - - ">="
162
170
  - !ruby/object:Gem::Version
163
- version: 3.2.0
171
+ version: '3.0'
164
172
  required_rubygems_version: !ruby/object:Gem::Requirement
165
173
  requirements:
166
174
  - - ">="
167
175
  - !ruby/object:Gem::Version
168
176
  version: '0'
169
177
  requirements: []
170
- rubygems_version: 3.4.22
178
+ rubygems_version: 3.5.1
171
179
  signing_key:
172
180
  specification_version: 4
173
181
  summary: A lightweight and experimental web framework for Ruby.
data/CHANGELOG.md DELETED
@@ -1,56 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
-
7
- ## [0.1.4] - 2023-25-11
8
-
9
- ### Fixed
10
-
11
- - Internal docmentation methods
12
- - Fix `post_params` from Resquest router class
13
-
14
- ### Added
15
-
16
- - Add basic documentation for usage. See [README.md](README.md) for more details.
17
-
18
- ## [0.1.3] - 2023-24-11
19
-
20
- ## [0.1.2] - 2023-23-11
21
-
22
- ### Added
23
-
24
- - Implemented a specific error handler for Content-Type related errors, enhancing the system's ability to respond appropriately based on whether the request Content-Type is JSON or HTML.
25
-
26
- ### Removed
27
-
28
- - Removed the debug gem from development dependencies, streamlining the development environment setup.
29
-
30
- ### Fixed
31
-
32
- - Fixed a bug that prevented the correct reading of the Content-Type header in requests, ensuring proper handling of content types.
33
-
34
- ## [0.1.1] - 2023-23-11
35
-
36
- ### Added
37
-
38
- - Introduced `Array.wrap` extension to the `Array` class for more reliable conversion of objects to arrays within the Lennarb router environment. This method ensures consistent array wrapping of single objects and `nil` values.
39
-
40
- ### Changed
41
-
42
- - Refactored the `put_header` method to use the `Array.wrap` method for more predictable header value handling.
43
- - Renamed methods to have a consistent `assign_` prefix to standardize the API interface:
44
- - `put_header` to `assign_header`
45
- - `write_body` to `assign_body`
46
- - `set_params` to `assign_params`
47
- - `update_status` to `assign_status`
48
-
49
- ### Deprecated
50
-
51
- ### Removed
52
-
53
- ### Fixed
54
-
55
- ### Security
56
-
data/LICENCE DELETED
@@ -1,24 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2023, Aristóteles Coutinho costa
4
-
5
- Permission is hereby granted, free of charge, to any person
6
- obtaining a copy of this software and associated documentation
7
- files (the "Software"), to deal in the Software without
8
- restriction, including without limitation the rights to use,
9
- copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the
11
- Software is furnished to do so, subject to the following
12
- conditions:
13
-
14
- The above copyright notice and this permission notice shall be
15
- included in all copies or substantial portions of the Software.
16
-
17
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24
- OTHER DEALINGS IN THE SOFTWARE.
data/README.md DELETED
@@ -1,229 +0,0 @@
1
- # Lennarb
2
-
3
- Lennarb is a experimental lightweight, fast, and modular web framework for Ruby based on Rack.
4
-
5
- image
6
-
7
- ## Table of Contents
8
-
9
- - [About](#about)
10
- - [Installation](#installation)
11
- - [Usage](#usage)
12
- - [Routing](#routing)
13
- - [Parameters](#parameters)
14
- - [Namespaces](#namespaces)
15
- - [Middlewares](#middlewares)
16
- - [Render HTML templates](#render-html-templates)
17
- - [Render JSON](#render-json)
18
- - [TODO](#todo)
19
- - [Development](#development)
20
- - [Contributing](#contributing)
21
-
22
- ## About
23
-
24
- Lennarb is designed to be simple and easy to use, while still providing the power and flexibility of a full-featured web framework. Also, that's how I affectionately call my wife.
25
-
26
- ## Installation
27
-
28
- Add this line to your application's Gemfile:
29
-
30
- ```rb
31
- gem 'lennarb'
32
- ```
33
-
34
- And then execute:
35
-
36
- ```bash
37
- $ bundle install
38
- ```
39
-
40
- Or install it yourself as:
41
-
42
- ```bash
43
- $ gem install lennarb
44
- ```
45
-
46
- ## Usage
47
-
48
- After installing, you can begin using Lennarb to build your modular web applications with Ruby. Here is an example of how to get started:
49
-
50
- ```rb
51
- app = Lenna::Base.new
52
-
53
- app.get('/hello/:name') do |req, res|
54
- name = req.params[:name]
55
-
56
- res.html("Hello #{name}!")
57
- end
58
-
59
- app.listen(8000)
60
- ```
61
-
62
- This example creates a new Lennarb application, defines a route for the `/hello/:name` path, and then starts the application on port 8000. When a request is made to the `/hello/:name` path, the application will respond with `Hello <name>!`, where `<name>` is the value of the `:name` parameter in the request path.
63
-
64
- ### Routing
65
-
66
- Lennarb uses a simple routing system that allows you to define routes for your application. Routes are defined using the `get`, `post`, `put`, `patch`, `delete`. These methods take three arguments: the path to match, an Array of the middlewares that can be apply on the current route and a block to execute when a request is made to the path. The block is passed two arguments: the [`request`](https://github.com/aristotelesbr/lennarb/blob/main/lib/lenna/router/request.rb) object and the [`response`](https://github.com/aristotelesbr/lennarb/blob/main/lib/lenna/router/response.rb) object. The request object contains information about the request, such as the request method, headers, and body. The response object contains methods for setting the response status code, headers, and body. Ex.
67
-
68
- ```rb
69
- app.get('/hello') do |_req, res|
70
- res.html('Hello World!')
71
- end
72
- ```
73
-
74
- The example above defines a route for the `/hello` path. When a request is made to the `/hello` path, the application will respond with `Hello World!`.
75
-
76
- #### Parameters
77
-
78
- Lennarb allows you to define parameters in your routes. Parameters are defined using the `:` character, followed by the name of the parameter. Parameters are passed to the route block as a hash in the request object's `params` property.
79
-
80
- ```rb
81
- app.get('/hello/:name') do |req, res|
82
- name = req.params[:name]
83
-
84
- res.html("Hello #{name}!")
85
- end
86
- ```
87
-
88
- The example above defines a route for the `/hello/:name` path. When a request is made to the `/hello/:name` path, the application will respond with `Hello <name>!`, where `<name>` is the value of the `:name` parameter in the request path.
89
-
90
- #### namespaces
91
-
92
- Lennarb allows you to define namespaces in your routes. Namespaces are defined using the `namespace` method on the application object. Namespaces are passed to the route block as a hash in the request object's `params` property.
93
-
94
- ```rb
95
- app.namespace('/api') do |router|
96
- roter.get('/hello') do |_req, res|
97
- res.html('Hello World!')
98
- end
99
- end
100
- ```
101
-
102
- The example above defines a namespace for the `/api` path. When a request is made to the `/api/hello` path, the application will respond with `Hello World!`.
103
-
104
- #### Middlewares
105
-
106
- The Lennarb application object has a `use` method that allows you to add middleware to your application. Middleware is defined using the `use` method on the application object. Ex.
107
-
108
- ```rb
109
- app.get('/hello') do |_req, res|
110
- res.html('Hello World!')
111
- end
112
-
113
- app.use(Lenna::Middleware::Logger)
114
- ```
115
-
116
- You can also define middleware for specific route.
117
-
118
- ```rb
119
- app.get('/hello', TimeMiddleware) do |_req, res|
120
- res.html('Hello World!')
121
- end
122
- ```
123
-
124
- You can create your own middleware by creating a class that implements the `call` method. This methods receive three
125
-
126
- ```rb
127
- class TimeMiddleware
128
- def call(req, res, next_middleware)
129
- puts Time.now
130
-
131
- req.headers['X-Time'] = Time.now
132
-
133
- next_middleware.call
134
- end
135
- end
136
- ```
137
-
138
- Or using a lambda functions.
139
-
140
- ```rb
141
- TimeMiddleware = ->(req, res, next_middleware) do
142
- puts Time.now
143
-
144
- req.headers['X-Time'] = Time.now
145
-
146
- next_middleware.call
147
- end
148
- ```
149
-
150
- So you can use it like this:
151
-
152
- ```rb
153
- app.get('/hello', TimeMiddleware) do |_req, res|
154
- res.html('Hello World!')
155
- end
156
- ```
157
-
158
- And you can use multiple middlewares on the same route.
159
-
160
- ```rb
161
- app.get('/hello', [TimeMiddleware, LoggerMiddleware]) do |_req, res|
162
- res.html('Hello World!')
163
- end
164
- ```
165
-
166
- ### Render HTML templates
167
-
168
- Lennarb allows you to render HTML templates using the `render` method on the response object. The `render` method takes two arguments: the name of the template file, and a hash of variables to pass to the template.
169
-
170
- ```rb
171
- app.get('/hello') do |_req, res|
172
- res.render('hello', locals: { name: 'World' })
173
- end
174
- ```
175
-
176
- The example above renders the `hello.html.erb` template, passing the `name` variable to the template.
177
- By default, Lennarb looks for templates in the `views` directory in root path. You can change this specifying the path for `views` in render method. Ex.
178
-
179
- ```rb
180
- app.get('/hello') do |_req, res|
181
- res.render('hello', path: 'app/web/templates', locals: { name: 'World' })
182
- end
183
- ```
184
-
185
- ### Render JSON
186
-
187
- Lennarb allows you to render JSON using the `json` method on the response object. The `json` method takes one argument: the object to render as JSON.
188
-
189
- ```rb
190
- app.get('/hello') do |_req, res|
191
- res.json(data: { message: 'Hello World!' })
192
- end
193
- ```
194
-
195
- The example above renders the `{ message: 'Hello World!' }` object as JSON.
196
-
197
-
198
-
199
- ### TODO
200
-
201
- - [ ] Add support for mime types
202
- - [ ] Add support for sessions
203
- - [ ] Add support for websockets
204
- - [ ] Add support for streaming
205
- - [ ] Add support for CORS
206
- - [ ] Add support for CSRF
207
- - [ ] Add support for caching
208
- - [ ] Add support for gzip compression
209
- - [ ] Add support for SSL
210
- - [ ] Add support for HTTP/2
211
- - [ ] Add support for HTTP/3
212
-
213
- ## Development
214
-
215
- To set up the development environment after cloning the repo, run:
216
-
217
- ```bash
218
- $ bin/setup
219
- ```
220
-
221
- To run the tests, run:
222
-
223
- ```bash
224
- $ rake test
225
- ```
226
-
227
- ## Contributing
228
-
229
- Bug reports and pull requests are welcome on GitHub at https://github.com/aristotelesbr/lennarb.
data/lib/lenna/base.rb DELETED
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # External dependencies
4
- require 'puma'
5
-
6
- # Internal dependencies
7
- require 'lenna/middleware/default/error_handler'
8
- require 'lenna/middleware/default/logging'
9
- require 'lenna/router'
10
-
11
- module Lenna
12
- # The base class is used to start the server.
13
- class Base < Router
14
- DEFAULT_PORT = 3000
15
- private_constant :DEFAULT_PORT
16
- DEFAULT_HOST = 'localhost'
17
- private_constant :DEFAULT_HOST
18
-
19
- # This method will start the server.
20
- #
21
- # @param port [Integer] The port to listen on (default: 3000)
22
- # @param host [String] The host to listen on (default: '
23
- # @return [void]
24
- #
25
- # @example
26
- # app = Lenna::Base.new
27
- # app.listen(8080)
28
- # # => ⚡ Listening on localhost:8080
29
- #
30
- # or specify the host and port
31
- #
32
- # app = Lenna::Base.new
33
- # app.listen(8000, host: '0.0.0.0')
34
- # # => ⚡ Listening on 0.0.0.0:8000
35
- #
36
- # @api public
37
- #
38
- # @todo: Add Lenna::Server to handle the server logic
39
- #
40
- # @since 0.1.0
41
- def listen(port = DEFAULT_PORT, host: DEFAULT_HOST, **)
42
- puts "⚡ Listening on #{host}:#{port}. \n Use Ctrl-C to stop the server."
43
-
44
- # Add the logging middleware to the stack
45
- use(Middleware::Default::Logging, Middleware::Default::ErrorHandler)
46
-
47
- server = ::Puma::Server.new(self, **)
48
- server.add_tcp_listener(host, port)
49
- server.run.join
50
- end
51
- end
52
- end