lennarb 0.4.0 → 0.4.2
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/changelog.md +25 -0
- data/lib/lennarb/response.rb +1 -1
- data/lib/lennarb/version.rb +1 -1
- data/lib/lennarb.rb +53 -37
- 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: d8f83fbde3862f89138c06960e7e10d92febf1b2568ec1ac7d5f414e56eb7861
|
4
|
+
data.tar.gz: 2ae1191814fc395c684f7d3b52a3d16d41cdb722d61ebd1c18937ab7e2eeff00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bf21b6aeaaafc3b1c1f795ae356883ad6c4581506527f6b92b2a10b823770e6d5a8249dc7ebacc0776e0d5a8b4d10a818dcb05ac22ec5cb48e84c7f027d9925
|
7
|
+
data.tar.gz: 96a9067abdf1f6062da9cac71fd79df3a7da8d01a19d662419c9f7d9498438b57299074a5ac2ac86b44271f263e0a52c69d8f48e69c7843177191a653d68e508
|
data/changelog.md
CHANGED
@@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [0.4.1] - 2024-08-02
|
9
|
+
|
10
|
+
### Change
|
11
|
+
|
12
|
+
- Change behavior of `Lennarb::ApplicationBase` class to be the base class of the `Lennarb` class. Now, the `Lennarb` class is a subclass of `Lennarb::ApplicationBase` class.
|
13
|
+
|
14
|
+
That permits to create a new application with the `Lennarb::ApplicationBase` class and use http methods to create the routes. Ex.
|
15
|
+
|
16
|
+
```rb
|
17
|
+
# app.rb
|
18
|
+
|
19
|
+
require 'lennarb'
|
20
|
+
|
21
|
+
class MyApp < Lennarb::ApplicationBase
|
22
|
+
get '/hello' do |req, res|
|
23
|
+
res.html('Hello World')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
```
|
27
|
+
|
28
|
+
### Removed
|
29
|
+
|
30
|
+
- Remove `Lennarb::Application` module from the project. Now, the `Lennarb` class is the main class of the project.
|
31
|
+
|
32
|
+
|
8
33
|
## [0.4.0] - 2024-07-02
|
9
34
|
|
10
35
|
### Added
|
data/lib/lennarb/response.rb
CHANGED
data/lib/lennarb/version.rb
CHANGED
data/lib/lennarb.rb
CHANGED
@@ -27,6 +27,7 @@ class Lennarb
|
|
27
27
|
#
|
28
28
|
attr_reader :root
|
29
29
|
|
30
|
+
@routes = []
|
30
31
|
# Initialize the application
|
31
32
|
#
|
32
33
|
# @yield { ... } The application
|
@@ -74,11 +75,15 @@ class Lennarb
|
|
74
75
|
#
|
75
76
|
# @returns [void]
|
76
77
|
#
|
77
|
-
def get(path, &block) =
|
78
|
-
def
|
79
|
-
def
|
80
|
-
def
|
81
|
-
def
|
78
|
+
def get(path, &block) = add_route(path, :GET, block)
|
79
|
+
def put(path, &block) = add_route(path, :PUT, block)
|
80
|
+
def post(path, &block) = add_route(path, :POST, block)
|
81
|
+
def head(path, &block) = add_route(path, :HEAD, block)
|
82
|
+
def patch(path, &block) = add_route(path, :PATCH, block)
|
83
|
+
def delete(path, &block) = add_route(path, :DELETE, block)
|
84
|
+
def options(path, &block) = add_route(path, :OPTIONS, block)
|
85
|
+
|
86
|
+
private
|
82
87
|
|
83
88
|
# Add a route
|
84
89
|
#
|
@@ -88,39 +93,18 @@ class Lennarb
|
|
88
93
|
#
|
89
94
|
# @returns [void]
|
90
95
|
#
|
91
|
-
def
|
96
|
+
def add_route(path, http_method, block)
|
92
97
|
parts = SplitPath[path]
|
93
98
|
@root.add_route(parts, http_method, block)
|
94
99
|
end
|
95
100
|
|
96
|
-
# Base
|
97
|
-
# and call the Lennarb instance.
|
101
|
+
# Base class for Lennarb applications
|
98
102
|
#
|
99
|
-
|
100
|
-
|
101
|
-
#
|
102
|
-
# @parameter [Class] base
|
103
|
-
#
|
104
|
-
# @returns [void]
|
105
|
-
#
|
106
|
-
def self.included(base) = base.extend(ClassMethods)
|
107
|
-
|
108
|
-
# Call the Lennarb instance
|
109
|
-
#
|
110
|
-
# @parameter [Hash] env
|
111
|
-
#
|
112
|
-
# @returns [Array]
|
113
|
-
#
|
114
|
-
def call(env) = self.class.lennarb_instance.call(env)
|
103
|
+
class ApplicationBase < Lennarb
|
104
|
+
@routes = []
|
115
105
|
|
116
|
-
|
117
|
-
|
118
|
-
module ClassMethods
|
119
|
-
# Get the Lennarb instance
|
120
|
-
#
|
121
|
-
# @returns [Lennarb]
|
122
|
-
#
|
123
|
-
def lennarb_instance = @lennarb_instance ||= Lennarb.new
|
106
|
+
class << self
|
107
|
+
attr_reader :routes
|
124
108
|
|
125
109
|
# Add a route
|
126
110
|
#
|
@@ -129,11 +113,43 @@ class Lennarb
|
|
129
113
|
#
|
130
114
|
# @returns [void]
|
131
115
|
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
116
|
+
%i[get post put patch delete].each do |http_method|
|
117
|
+
define_method(http_method) do |path, &block|
|
118
|
+
routes << { method: http_method, path:, proc: block }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Inherited hook
|
124
|
+
#
|
125
|
+
# @parameter [Class] subclass
|
126
|
+
#
|
127
|
+
# @returns [void]
|
128
|
+
#
|
129
|
+
def self.inherited(subclass)
|
130
|
+
super
|
131
|
+
subclass.instance_variable_set(:@routes, routes.dup)
|
132
|
+
end
|
133
|
+
|
134
|
+
# Initialize the application
|
135
|
+
#
|
136
|
+
# @returns [ApplicationBase]
|
137
|
+
#
|
138
|
+
def initialize
|
139
|
+
super
|
140
|
+
setup_routes
|
141
|
+
end
|
142
|
+
|
143
|
+
private
|
144
|
+
|
145
|
+
# Setup the routes
|
146
|
+
#
|
147
|
+
# @returns [void]
|
148
|
+
#
|
149
|
+
def setup_routes
|
150
|
+
self.class.routes.each do |route_info|
|
151
|
+
__send__(route_info[:method], route_info[:path], &route_info[:proc])
|
152
|
+
end
|
137
153
|
end
|
138
154
|
end
|
139
155
|
end
|
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.4.
|
4
|
+
version: 0.4.2
|
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-02-
|
11
|
+
date: 2024-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|