lennarb 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0fafe6e0a4a4fcb12d0cb7d75187b89c5ff2a8f4847bdab4db666d670fd1d40e
4
- data.tar.gz: 43739df71271e6410f691b19d0e31c64ea5e883ae79150a3d0055d17a200fe8a
3
+ metadata.gz: fb597d27bfaffebc72a4b7aa52f74dd0c5e94c60d401c4f8c30558246509a59d
4
+ data.tar.gz: 0a49adeeb50aee3f5d09a641535d9e230aadeb40d69dc9a1883551641f045999
5
5
  SHA512:
6
- metadata.gz: 8015dceb914f8bf52ee77eff7faf3adca26cdb020a3acba0ce3cc58ecd7eec338e84afe87fcd691867e087a646875b06a9f278c220b25f4f627bc87ff7288306
7
- data.tar.gz: c9a7b74731ac3fe4e607396647931656628e1df03968069891d65189b0f387df44d89054191a34a41bdaf7a3381ad6c2486f91fba13dfd4b5a3b04a79f299af7
6
+ metadata.gz: 4a682640f80f02dc84fba9e1f9aa7f666b68b08101c19e2ab406dc9e5367352be25bf7f9f91b26b39ff2f92f9a2c472cc7ba1c306679970fa510fbca73806a04
7
+ data.tar.gz: cb431441f0481b65774ed39f83bf12bb19a2316e3815bfba88388cefc7a641c712777727de51a3a03f60fde4a6de078b2c34d4abb25481835958cc9bb4eb2377
@@ -0,0 +1,8 @@
1
+ # Released under the MIT License.
2
+ # Copyright, 2023, by Aristóteles Coutinho.
3
+
4
+ # [Choice] Ruby version: 3, 3.0, 2, 2.7, 2.6
5
+ ARG VARIANT="3"
6
+ FROM mcr.microsoft.com/devcontainers/ruby:${VARIANT}
7
+
8
+ RUN apt-get update
@@ -0,0 +1,20 @@
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/ruby
3
+ {
4
+ "name": "Lennarb project development",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ // "image": "mcr.microsoft.com/devcontainers/ruby:1-3.2-bullseye"
7
+ "build": {
8
+ "dockerfile": "Dockerfile"
9
+ }
10
+ // Features to add to the dev container. More info: https://containers.dev/features.
11
+ // "features": {},
12
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
13
+ // "forwardPorts": [],
14
+ // Use 'postCreateCommand' to run commands after the container is created.
15
+ // "postCreateCommand": "ruby --version",
16
+ // Configure tool-specific properties.
17
+ // "customizations": {},
18
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
19
+ // "remoteUser": "root"
20
+ }
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+
7
+ [*.{yml,yaml}]
8
+ indent_style = space
9
+ indent_size = 2
@@ -0,0 +1,58 @@
1
+ name: Coverage
2
+
3
+ on: [push, pull_request]
4
+
5
+ permissions:
6
+ contents: read
7
+
8
+ env:
9
+ CONSOLE_OUTPUT: XTerm
10
+ COVERAGE: PartialSummary
11
+ BUNDLE_WITH: maintenance
12
+
13
+ jobs:
14
+ test:
15
+ name: ${{matrix.ruby}} on ${{matrix.os}}
16
+ runs-on: ${{matrix.os}}-latest
17
+
18
+ strategy:
19
+ matrix:
20
+ os:
21
+ - ubuntu
22
+ - macos
23
+
24
+ ruby:
25
+ - '3.4'
26
+
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{matrix.ruby}}
32
+ bundler-cache: true
33
+
34
+ - name: Run tests
35
+ timeout-minutes: 5
36
+ run: bundle exec rake
37
+
38
+ - uses: actions/upload-artifact@v4
39
+ with:
40
+ name: coverage-${{matrix.os}}-${{matrix.ruby}}
41
+ path: .covered.db
42
+
43
+ validate:
44
+ needs: test
45
+ runs-on: ubuntu-latest
46
+
47
+ steps:
48
+ - uses: actions/checkout@v4
49
+ - uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: '3.4'
52
+ bundler-cache: true
53
+
54
+ - uses: actions/download-artifact@v4
55
+
56
+ - name: Validate coverage
57
+ timeout-minutes: 5
58
+ run: bundle exec bake covered:validate --paths */.covered.db \;
@@ -0,0 +1,47 @@
1
+ name: Documentation
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ workflow_dispatch:
9
+
10
+ permissions:
11
+ contents: read
12
+ pages: write
13
+ id-token: write
14
+
15
+ concurrency:
16
+ group: 'pages'
17
+ cancel-in-progress: true
18
+
19
+ env:
20
+ CONSOLE_OUTPUT: XTerm
21
+ BUNDLE_WITH: maintenance
22
+
23
+ jobs:
24
+ generate:
25
+ runs-on: ubuntu-latest
26
+
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+
30
+ - uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: '3.4'
33
+ bundler-cache: true
34
+
35
+ - name: Installing packages
36
+ run: sudo apt-get install wget
37
+
38
+ - name: Prepare GitHub Pages
39
+ run: bundle exec bake github:pages:prepare --directory docs
40
+
41
+ - name: Generate documentation
42
+ timeout-minutes: 5
43
+ run: bundle exec bake utopia:project:static --force no
44
+
45
+ - name: Deploy GitHub Pages
46
+ run: bundle exec bake github:pages:commit --directory docs
47
+
@@ -0,0 +1,27 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ pull_request:
9
+
10
+ jobs:
11
+ build:
12
+ runs-on: ubuntu-latest
13
+ name: Ruby ${{ matrix.ruby }}
14
+ strategy:
15
+ matrix:
16
+ ruby:
17
+ - '3.4'
18
+
19
+ steps:
20
+ - uses: actions/checkout@v4
21
+ - name: Set up Ruby
22
+ uses: ruby/setup-ruby@v1
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - name: Run the default task
27
+ run: bundle exec rake test
@@ -0,0 +1,49 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ permissions:
6
+ contents: read
7
+
8
+ env:
9
+ CONSOLE_OUTPUT: XTerm
10
+
11
+ jobs:
12
+ test:
13
+ name: ${{matrix.ruby}} on ${{matrix.os}}
14
+ runs-on: ${{matrix.os}}-latest
15
+ continue-on-error: ${{matrix.experimental}}
16
+
17
+ strategy:
18
+ matrix:
19
+ os:
20
+ - ubuntu
21
+ - macos
22
+
23
+ ruby:
24
+ - '3.3'
25
+ - '3.4'
26
+
27
+ experimental: [false]
28
+
29
+ include:
30
+ - os: ubuntu
31
+ ruby: truffleruby
32
+ experimental: true
33
+ - os: ubuntu
34
+ ruby: jruby
35
+ experimental: true
36
+ - os: ubuntu
37
+ ruby: head
38
+ experimental: true
39
+
40
+ steps:
41
+ - uses: actions/checkout@v4
42
+ - uses: ruby/setup-ruby@v1
43
+ with:
44
+ ruby-version: ${{matrix.ruby}}
45
+ bundler-cache: true
46
+
47
+ - name: Run tests
48
+ timeout-minutes: 10
49
+ run: bundle exec rake test
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /pkg/
3
+ /gems.locked
4
+ /.covered.db
5
+ /external
6
+ /docs
7
+ .DS_Store
8
+ *.gem
9
+ *.rbc
10
+ .git
11
+ .ruby-lsp
12
+ coverage/
data/.standard.yml ADDED
@@ -0,0 +1,23 @@
1
+ ruby_version: 3.4.1
2
+
3
+ ignore:
4
+ - 'bin/**/*'
5
+ - 'vendor/**/*'
6
+ - 'db/schema.rb'
7
+
8
+ plugins:
9
+ - standard-custom
10
+ - standard-performance
11
+
12
+ standard_custom:
13
+ rules:
14
+ lambda_call_style:
15
+ enabled: false
16
+ style: "call"
17
+
18
+ lambda_syntax:
19
+ enabled: false
20
+ style: "line_count_dependent"
21
+
22
+ copyright_notice:
23
+ enabled: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 3.4.1
data/LICENCE ADDED
@@ -0,0 +1,24 @@
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/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: %i[test]
Binary file
data/benchmark/rps.png ADDED
Binary file
Binary file
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/lennarb"
4
+ # You can add fixtures and/or initialization code here to make experimenting
5
+ # with your gem easier. You can also use a different console, if you like.
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/bin/release ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'lennarb/version'
4
+ require 'colorize'
5
+
6
+ puts 'Generating gem version...'.green
7
+ system('bundle exec gem build lennarb.gemspec')
8
+ puts 'Gem version generated successfully'.green
9
+
10
+ puts 'Installing gem version...'.green
11
+
12
+ version = Lennarb::VERSION
13
+ system("gem install ./lennarb-#{version}.gem")
14
+ puts 'Lenna installed successfully'.green
15
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/changelog.md CHANGED
@@ -7,6 +7,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.4.0] - 2025-02-09
11
+
12
+ ### Changed
13
+
14
+ - The `freeze!` method was removed from the `Lennarb` class. Use `initializer!` to build and freeze the application.
15
+
16
+ ```rb
17
+ # app.rb
18
+
19
+ require 'lennarb'
20
+
21
+ MyApp = Lennarb.new do |router|
22
+ router.get '/hello' do |req, res|
23
+ res.html('Hello World')
24
+ end
25
+ end
26
+
27
+ MyApp.initializer!
28
+
29
+ run MyApp
30
+ ```
31
+
32
+ ### Remove
33
+
34
+ - Removes bake scripts from the project. Use `rack'` to run tasks.
35
+ - Removes `plugin` module and basic plugins from the project. Now, the `Lennarb` class is the main class of the project.
36
+ - Removes unnecessary tests.
37
+ - Removes `.rubocop.yml` file from the project. Now, the project uses the default configuration of the `standard` gem.
38
+
39
+ ### Added
40
+
41
+ - Add `simplecov` gem to generate the test coverage report.
42
+ - Add `m` gem to run the tests.
43
+
10
44
  ## [1.3.0] - 2024-11-21
11
45
 
12
46
  ### Added
@@ -78,9 +112,9 @@ That permits to create a new application with the `Lennarb::ApplicationBase` cla
78
112
  require 'lennarb'
79
113
 
80
114
  class MyApp < Lennarb::ApplicationBase
81
- get '/hello' do |req, res|
82
- res.html('Hello World')
83
- end
115
+ get '/hello' do |req, res|
116
+ res.html('Hello World')
117
+ end
84
118
  end
85
119
  ```
86
120
 
@@ -88,7 +122,6 @@ end
88
122
 
89
123
  - Remove `Lennarb::Application` module from the project. Now, the `Lennarb` class is the main class of the project.
90
124
 
91
-
92
125
  ## [0.4.0] - 2024-07-02
93
126
 
94
127
  ### Added
@@ -105,9 +138,9 @@ require 'lennarb'
105
138
  class MyApp
106
139
  include Lennarb::ApplicationBase
107
140
 
108
- get '/hello' do |req, res|
109
- res.html('Hello World')
110
- end
141
+ get '/hello' do |req, res|
142
+ res.html('Hello World')
143
+ end
111
144
  end
112
145
  ```
113
146
 
data/exe/lenna CHANGED
@@ -1,14 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
2
 
4
3
  # Released under the MIT License.
5
- # Copyright, 2023, by Aristóteles Coutinho.
4
+ # Copyright, 2023-2025, by Aristóteles Coutinho.
6
5
 
7
6
  # Require the main file
8
7
  #
9
8
  # @private `Since v0.1`
10
9
  #
11
- require 'lennarb'
10
+ require "lennarb"
12
11
 
13
12
  # Show the version
14
13
  #
data/gems.rb ADDED
@@ -0,0 +1,29 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lennarb.gemspec
4
+ gemspec
5
+
6
+ group :maintenance, optional: true do
7
+ # [https://rubygems.org/gems/bake]
8
+ # Bake is a Ruby library that helps you to create a new project.
9
+ gem "bake"
10
+ # [https://rubygems.org/gems/covered]
11
+ # Covered is a Ruby library that helps you to test your project.
12
+ gem "covered"
13
+ # [https://rubygems.org/gems/bake-gem]
14
+ # Bake Gem is a Bake extension that helps you to create a new Ruby
15
+ # gem.
16
+ gem "bake-gem"
17
+ # [https://rubygems.org/gems/bake-modernize]
18
+ # Bake Modernize is a Bake extension that helps you to modernize your
19
+ # Ruby code.
20
+ gem "bake-modernize"
21
+ # [https://rubygems.org/gems/bake-github-pages]
22
+ # Bake Github Pages is a Bake extension that helps you to publish your
23
+ # project documentation to Github Pages.
24
+ gem "bake-github-pages"
25
+ # [https://rubygems.org/gems/utpia-project]
26
+ # Utopia Project is a Bake extension that helps you to create a new
27
+ # project.
28
+ gem "utopia-project"
29
+ end
@@ -0,0 +1,201 @@
1
+ # Getting Started with Lennarb
2
+
3
+ ## Overview
4
+
5
+ Lennarb is a minimalist, thread-safe Rack-based web framework for Ruby that focuses on simplicity and performance. It provides a clean routing DSL and straightforward request/response handling.
6
+
7
+ ## Installation
8
+
9
+ Add Lennarb to your project's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'lennarb'
13
+ ```
14
+
15
+ Or install it directly via RubyGems:
16
+
17
+ ```bash
18
+ gem install lennarb
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ### Basic Application
24
+
25
+ Create a new file named `config.ru`:
26
+
27
+ ```ruby
28
+ require 'lennarb'
29
+
30
+ app = Lennarb.new do |app|
31
+ app.get '/' do |req, res|
32
+ res.status = 200
33
+ res.html('<h1>Welcome to Lennarb!</h1>')
34
+ end
35
+ end
36
+
37
+ app.initializer!
38
+ run app
39
+ ```
40
+
41
+ Start the server:
42
+
43
+ ```bash
44
+ rackup
45
+ ```
46
+
47
+ Your application will be available at `http://localhost:9292`.
48
+
49
+ ## Core Concepts
50
+
51
+ ### Request Handling
52
+
53
+ Each route handler receives two arguments:
54
+
55
+ - `req`: A Request object wrapping the Rack environment
56
+ - `res`: A Response object for building the HTTP response
57
+
58
+ ### Response Types
59
+
60
+ Lennarb provides three main response helpers:
61
+
62
+ ```rb
63
+ app.get '/text' do |req, res|
64
+ res.text('Plain text response')
65
+ end
66
+
67
+ app.get '/html' do |req, res|
68
+ res.html('<h1>HTML response</h1>')
69
+ end
70
+
71
+ app.get '/json' do |req, res|
72
+ res.json('{"message": "JSON response"}')
73
+ end
74
+ ```
75
+
76
+ ### Redirects
77
+
78
+ ```ruby
79
+ app.get '/redirect' do |req, res|
80
+ res.redirect('/new-location', 302) # 302
81
+ end
82
+ ```
83
+
84
+ Routes are defined using HTTP method helpers:
85
+
86
+ ```ruby
87
+ app = Lennarb.new do |l|
88
+ # Basic route
89
+ l.get '/' do |req, res|
90
+ res.html('Home page')
91
+ end
92
+
93
+ # Route with parameters
94
+ l.get '/users/:id' do |req, res|
95
+ user_id = req.params[:id]
96
+ res.json("{\"id\": #{user_id}}")
97
+ end
98
+ end
99
+ ```
100
+
101
+ ### Route Parameters
102
+
103
+ Parameters from dynamic route segments are available in `req.params`:
104
+
105
+ ```ruby
106
+ app.get '/hello/:name' do |req, res|
107
+ name = req.params[:name]
108
+ res.text("Hello, #{name}!")
109
+ end
110
+ ```
111
+
112
+ ## Thread Safety
113
+
114
+ Lennarb is thread-safe by design:
115
+
116
+ - All request processing is synchronized using a mutex
117
+ - The router tree is frozen after initialization
118
+ - Response objects are created per-request
119
+
120
+ ## Application Lifecycle
121
+
122
+ ### Initialization
123
+
124
+ ```ruby
125
+ app = Lennarb.new do |l|
126
+ # Define routes and configuration
127
+ end
128
+
129
+ # Initialize and freeze the application
130
+ app.initializer!
131
+ ```
132
+
133
+ The `initializer!` method:
134
+
135
+ - Loads environment-specific dependencies
136
+ - Freezes the route tree
137
+ - Freezes the Rack application
138
+
139
+ ### Environment
140
+
141
+ Lennarb uses the `LENNA_ENV` environment variable (defaults to "development"):
142
+
143
+ ```bash
144
+ LENNA_ENV=production rackup
145
+ ```
146
+
147
+ ## Error Handling
148
+
149
+ Lennarb provides basic error handling:
150
+
151
+ ```ruby
152
+ app.get '/api' do |req, res|
153
+ # Errors are caught and return 500 with error message
154
+ raise "Something went wrong"
155
+ end
156
+ ```
157
+
158
+ Default error responses:
159
+
160
+ - 404 for unmatched routes
161
+ - 500 for application errors
162
+
163
+ ## Best Practices
164
+
165
+ 1. **Always call initializer!**
166
+
167
+ ```ruby
168
+ app = Lennarb.new { |l| ... }
169
+ app.initializer!
170
+ run app
171
+ ```
172
+
173
+ 2. **Set response status**
174
+
175
+ ```ruby
176
+ app.get '/api' do |req, res|
177
+ res.status = 200
178
+ res.json('{"status": "ok"}')
179
+ end
180
+ ```
181
+
182
+ 3. **Use appropriate response types**
183
+
184
+ ```ruby
185
+ # HTML for web pages
186
+ res.html('<h1>Web Page</h1>')
187
+
188
+ # JSON for APIs
189
+ res.json('{"data": "value"}')
190
+
191
+ # Text for simple responses
192
+ res.text('Hello')
193
+ ```
194
+
195
+ ## Support
196
+
197
+ For help and bug reports, please visit:
198
+
199
+ - GitHub Issues: [lennarb/issues](https://github.com/aristotelesbr/lennarb/issues)
200
+
201
+ Now you can run your app!
data/guides/links.yaml ADDED
@@ -0,0 +1,6 @@
1
+ getting-started:
2
+ order: 1
3
+ performance:
4
+ order: 2
5
+ response:
6
+ order: 3