chespirito 0.0.1
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 +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +39 -0
- data/README.md +56 -0
- data/chespirito.gemspec +18 -0
- data/lib/chespirito/app.rb +44 -0
- data/lib/chespirito/controller.rb +22 -0
- data/lib/chespirito/request.rb +34 -0
- data/lib/chespirito/response.rb +13 -0
- data/lib/chespirito.rb +9 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3ea44622e48fc4daec6a855f893208c3a3d5a243a4ea38ff0077e63e29fffc6d
|
4
|
+
data.tar.gz: a9717fab4ec5e1a1f2285c583f8e0ec85ce9188d6321e379f476a99e2a195ce0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92ba0c82376ec77860b8cda7b934da1a25bcd416a9827640957bafa074a317c411a3f39e39b7fd2e2e923c07ed28e624d5c03bd54262af1fe8650613333023bb
|
7
|
+
data.tar.gz: b98940782b5be8d742d8c7750d86e576d8ce886f9d2697a9a52e0df7aeb3376497a8b1288a641d831e83c0d881fb4e5b75f30fdf90baebbdbc98aed746239679
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
adelnor (0.0.6)
|
5
|
+
rack
|
6
|
+
ast (2.4.2)
|
7
|
+
byebug (11.1.3)
|
8
|
+
parallel (1.22.1)
|
9
|
+
parser (3.1.2.0)
|
10
|
+
ast (~> 2.4.1)
|
11
|
+
rack (2.2.3)
|
12
|
+
rainbow (3.1.1)
|
13
|
+
regexp_parser (2.4.0)
|
14
|
+
rexml (3.2.5)
|
15
|
+
rubocop (1.29.1)
|
16
|
+
parallel (~> 1.10)
|
17
|
+
parser (>= 3.1.0.0)
|
18
|
+
rainbow (>= 2.2.2, < 4.0)
|
19
|
+
regexp_parser (>= 1.8, < 3.0)
|
20
|
+
rexml (>= 3.2.5, < 4.0)
|
21
|
+
rubocop-ast (>= 1.17.0, < 2.0)
|
22
|
+
ruby-progressbar (~> 1.7)
|
23
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
24
|
+
rubocop-ast (1.18.0)
|
25
|
+
parser (>= 3.1.1.0)
|
26
|
+
ruby-progressbar (1.11.0)
|
27
|
+
unicode-display_width (2.1.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
aarch64-linux
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
adelnor
|
34
|
+
byebug
|
35
|
+
rack
|
36
|
+
rubocop
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
2.3.3
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# chespirito
|
2
|
+
|
3
|
+

|
4
|
+

|
5
|
+

|
6
|
+
|
7
|
+

|
8
|
+
[](https://github.com/rubocop/rubocop)
|
9
|
+
[](https://rubystyle.guide)
|
10
|
+
```
|
11
|
+
______ __ __ _______ _______..______ __ .______ __ .___________. ______
|
12
|
+
/ || | | | | ____| / || _ \ | | | _ \ | | | | / __ \
|
13
|
+
| ,----'| |__| | | |__ | (----`| |_) | | | | |_) | | | `---| |----`| | | |
|
14
|
+
| | | __ | | __| \ \ | ___/ | | | / | | | | | | | |
|
15
|
+
| `----.| | | | | |____.----) | | | | | | |\ \----.| | | | | `--' |
|
16
|
+
\______||__| |__| |_______|_______/ | _| |__| | _| `._____||__| |__| \______/
|
17
|
+
```
|
18
|
+
|
19
|
+
[chespirito](https://rubygems.org/gems/chespirito) is a dead simple, yet Rack-compatible, web framework written in Ruby.
|
20
|
+
|
21
|
+
## Requirements
|
22
|
+
|
23
|
+
Ruby
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
```bash
|
27
|
+
$ gem install chespirito
|
28
|
+
```
|
29
|
+
|
30
|
+
## Development tooling
|
31
|
+
|
32
|
+
Make and Docker
|
33
|
+
|
34
|
+
## Using make
|
35
|
+
|
36
|
+
```bash
|
37
|
+
$ make help
|
38
|
+
```
|
39
|
+
Output:
|
40
|
+
```
|
41
|
+
Usage: make <target>
|
42
|
+
help Prints available commands
|
43
|
+
bundle.install Installs the Ruby gems
|
44
|
+
bash Creates a container Bash
|
45
|
+
run.tests Runs Unit tests
|
46
|
+
rubocop Runs code linter
|
47
|
+
ci Runs code linter and unit tests in CI
|
48
|
+
sample.hello-app Runs a sample Hello World app
|
49
|
+
sample.login-app Runs a sample app with Login feature
|
50
|
+
gem.publish Publishes the gem to https://rubygems.org (auth required)
|
51
|
+
gem.yank Removes a specific version from the Rubygems
|
52
|
+
```
|
53
|
+
|
54
|
+
----
|
55
|
+
|
56
|
+
[ASCII art generator](http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20)
|
data/chespirito.gemspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'chespirito'
|
5
|
+
spec.version = '0.0.1'
|
6
|
+
spec.summary = 'Chespirito Ruby web framework'
|
7
|
+
spec.description = 'A dead simple, yet Rack-compatible, web framework written in Ruby'
|
8
|
+
spec.authors = ['Leandro Proença']
|
9
|
+
spec.email = 'leandronsp@gmail.com'
|
10
|
+
spec.files = Dir['lib/**/*'] + %w[Gemfile Gemfile.lock README.md chespirito.gemspec]
|
11
|
+
spec.homepage = 'https://github.com/leandronsp/chespirito'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
spec.add_runtime_dependency 'rack'
|
15
|
+
spec.add_runtime_dependency 'adelnor'
|
16
|
+
|
17
|
+
spec.required_ruby_version = '~> 3.0'
|
18
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './request'
|
4
|
+
|
5
|
+
module Chespirito
|
6
|
+
class App
|
7
|
+
def initialize
|
8
|
+
@routes = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
return unless block_given?
|
13
|
+
|
14
|
+
new.tap { |app| yield(app) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def register_route(verb, path, trait)
|
18
|
+
@routes[route_key(verb, path)] = trait
|
19
|
+
end
|
20
|
+
|
21
|
+
def lookup(request)
|
22
|
+
controller_klass, action = @routes[route_key(request.verb, request.path)]
|
23
|
+
|
24
|
+
return unless controller_klass
|
25
|
+
|
26
|
+
controller_klass.dispatch(action, request)
|
27
|
+
end
|
28
|
+
|
29
|
+
def route_key(verb, path) = "#{verb} #{path}"
|
30
|
+
|
31
|
+
def call(env)
|
32
|
+
request = ::Chespirito::Request.build(env)
|
33
|
+
response = lookup(request)
|
34
|
+
|
35
|
+
[
|
36
|
+
response.status,
|
37
|
+
response.headers,
|
38
|
+
[response.body]
|
39
|
+
]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.application = App.new
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './response'
|
4
|
+
|
5
|
+
module Chespirito
|
6
|
+
class Controller
|
7
|
+
attr_reader :request, :response
|
8
|
+
|
9
|
+
def initialize(request)
|
10
|
+
@request = request
|
11
|
+
@response = ::Chespirito::Response.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.dispatch(action, request)
|
15
|
+
new(request)
|
16
|
+
.tap { |controller| controller.send(action.to_sym) }
|
17
|
+
.then { |controller| controller.response }
|
18
|
+
end
|
19
|
+
|
20
|
+
def view(path) = File.read(path)
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rack'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Chespirito
|
7
|
+
class Request
|
8
|
+
attr_reader :verb, :path, :headers, :params, :cookies
|
9
|
+
|
10
|
+
def initialize(verb, path, headers: {}, params: {}, cookies: {})
|
11
|
+
@verb = verb
|
12
|
+
@path = path
|
13
|
+
|
14
|
+
@headers = headers
|
15
|
+
@params = params
|
16
|
+
@cookies = cookies
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.build(env)
|
20
|
+
rack_request = Rack::Request.new(env)
|
21
|
+
|
22
|
+
body_params = rack_request.post? ? (JSON.parse(rack_request.body.read) rescue {}) : {}
|
23
|
+
params = rack_request.params.merge(body_params)
|
24
|
+
|
25
|
+
new(
|
26
|
+
rack_request.request_method,
|
27
|
+
rack_request.path,
|
28
|
+
headers: rack_request.env,
|
29
|
+
params: params,
|
30
|
+
cookies: rack_request.cookies
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/chespirito.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chespirito
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leandro Proença
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-05-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: adelnor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A dead simple, yet Rack-compatible, web framework written in Ruby
|
42
|
+
email: leandronsp@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- Gemfile
|
48
|
+
- Gemfile.lock
|
49
|
+
- README.md
|
50
|
+
- chespirito.gemspec
|
51
|
+
- lib/chespirito.rb
|
52
|
+
- lib/chespirito/app.rb
|
53
|
+
- lib/chespirito/controller.rb
|
54
|
+
- lib/chespirito/request.rb
|
55
|
+
- lib/chespirito/response.rb
|
56
|
+
homepage: https://github.com/leandronsp/chespirito
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubygems_version: 3.3.3
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Chespirito Ruby web framework
|
79
|
+
test_files: []
|