lennarb 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lennarb/version.rb +1 -1
- data/lib/lennarb.rb +51 -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: 0e395a91c3650883770feaf41c00a2be532f9ac0b3919a6ed26fcc4758ae3319
|
4
|
+
data.tar.gz: 25f09b0d53fb906eee6cd73197b970a01213a64ee4e8e0052e8bc73dca506d0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 034171202b487ef2b9de9fd21995df2918f6e4da6427088c665644646f34e8d3d4e4238b8708de2fb89a3303fd9d3d3f334c8402ee66ba70fdb889f8be7eca00
|
7
|
+
data.tar.gz: 66308251d5eaf6361f8e4d464858a068dfeaa49051d2cfb1157e2ca52a21338639ba7af8ceb92bba15ca8bbed76124a493c30d58563b1c0403fc403c0946ad87
|
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,13 @@ class Lennarb
|
|
74
75
|
#
|
75
76
|
# @returns [void]
|
76
77
|
#
|
77
|
-
def get(path, &block) =
|
78
|
-
def post(path, &block) =
|
79
|
-
def put(path, &block) =
|
80
|
-
def patch(path, &block) =
|
81
|
-
def delete(path, &block) =
|
78
|
+
def get(path, &block) = add_route(path, :GET, block)
|
79
|
+
def post(path, &block) = add_route(path, :POST, block)
|
80
|
+
def put(path, &block) = add_route(path, :PUT, block)
|
81
|
+
def patch(path, &block) = add_route(path, :PATCH, block)
|
82
|
+
def delete(path, &block) = add_route(path, :DELETE, block)
|
83
|
+
|
84
|
+
private
|
82
85
|
|
83
86
|
# Add a route
|
84
87
|
#
|
@@ -88,39 +91,18 @@ class Lennarb
|
|
88
91
|
#
|
89
92
|
# @returns [void]
|
90
93
|
#
|
91
|
-
def
|
94
|
+
def add_route(path, http_method, block)
|
92
95
|
parts = SplitPath[path]
|
93
96
|
@root.add_route(parts, http_method, block)
|
94
97
|
end
|
95
98
|
|
96
|
-
# Base
|
97
|
-
# and call the Lennarb instance.
|
99
|
+
# Base class for Lennarb applications
|
98
100
|
#
|
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)
|
101
|
+
class ApplicationBase < Lennarb
|
102
|
+
@routes = []
|
115
103
|
|
116
|
-
|
117
|
-
|
118
|
-
module ClassMethods
|
119
|
-
# Get the Lennarb instance
|
120
|
-
#
|
121
|
-
# @returns [Lennarb]
|
122
|
-
#
|
123
|
-
def lennarb_instance = @lennarb_instance ||= Lennarb.new
|
104
|
+
class << self
|
105
|
+
attr_reader :routes
|
124
106
|
|
125
107
|
# Add a route
|
126
108
|
#
|
@@ -129,11 +111,43 @@ class Lennarb
|
|
129
111
|
#
|
130
112
|
# @returns [void]
|
131
113
|
#
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
114
|
+
%i[get post put patch delete].each do |http_method|
|
115
|
+
define_method(http_method) do |path, &block|
|
116
|
+
routes << { method: http_method, path:, proc: block }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Inherited hook
|
122
|
+
#
|
123
|
+
# @parameter [Class] subclass
|
124
|
+
#
|
125
|
+
# @returns [void]
|
126
|
+
#
|
127
|
+
def self.inherited(subclass)
|
128
|
+
super
|
129
|
+
subclass.instance_variable_set(:@routes, routes.dup)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Initialize the application
|
133
|
+
#
|
134
|
+
# @returns [ApplicationBase]
|
135
|
+
#
|
136
|
+
def initialize
|
137
|
+
super
|
138
|
+
setup_routes
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
# Setup the routes
|
144
|
+
#
|
145
|
+
# @returns [void]
|
146
|
+
#
|
147
|
+
def setup_routes
|
148
|
+
self.class.routes.each do |route_info|
|
149
|
+
__send__(route_info[:method], route_info[:path], &route_info[:proc])
|
150
|
+
end
|
137
151
|
end
|
138
152
|
end
|
139
153
|
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.1
|
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
|