eredor 0.1.0 → 0.2.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 +4 -4
- data/README.md +33 -16
- data/lib/eredor/version.rb +1 -1
- data/lib/eredor.rb +31 -4
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '07877c607d2d4cd1c6ad3bf504d48f8cc19c70bd6cfacfe344dd17ac2d479796'
|
|
4
|
+
data.tar.gz: cee85827f625435e7e93a205c3ba50403ca68cdb8794fb49bb5f5bf72051ff63
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 64e1c90f1d916710ba2af39917f1dcb59fe7ea381cc733a538e24ced5dad8c3e8aa4e432686aea5663dd05bbb8b589fc47849ced65f22c5909442c5bced64032
|
|
7
|
+
data.tar.gz: 4a68d9b223c815b08c367bf932dbf2cde65212ba6bd39a91abbfc616c50d892708e57445acab89122f581eeb91cd55d32fe4072ba86b101a030255d029109dd0
|
data/README.md
CHANGED
|
@@ -1,38 +1,55 @@
|
|
|
1
|
-
# Eredor
|
|
1
|
+
# 🏔️ **Eredor**
|
|
2
2
|
|
|
3
|
-
TODO: Delete this and the text below, and describe your gem
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
[](https://rubygems.org/gems/eredor)
|
|
5
|
+
[](https://rubygems.org/gems/eredor)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://github.com/devguilhermeribeiiro/eredor)
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
> Eredor is a minimal set of OOP-based classes to help you develop small web applications without a dedicated framework. No magic, just Ruby.
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
---
|
|
12
|
+
## ⚡ **Instalation**
|
|
10
13
|
|
|
11
|
-
Install
|
|
14
|
+
Install via [RubyGems.org](https://rubygems.org/gems/eredor):
|
|
12
15
|
|
|
13
16
|
```bash
|
|
14
|
-
|
|
17
|
+
gem install eredor
|
|
15
18
|
```
|
|
16
|
-
|
|
17
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
19
|
+
Or add to your Gemfile:
|
|
18
20
|
|
|
19
21
|
```bash
|
|
20
|
-
|
|
22
|
+
bundle add eredor
|
|
23
|
+
bundle install
|
|
21
24
|
```
|
|
22
25
|
|
|
23
26
|
## Usage
|
|
24
27
|
|
|
25
|
-
|
|
28
|
+
Add to your config.ru:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
require 'rack'
|
|
32
|
+
require 'eredor'
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
run do |env|
|
|
35
|
+
request = Rack::Request.new(env)
|
|
36
|
+
router = Eredor::Router.new(request)
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
router.get '/' do
|
|
39
|
+
'<h1>Hello from Eredor</h1>'
|
|
40
|
+
end
|
|
30
41
|
|
|
31
|
-
|
|
42
|
+
router.handle
|
|
43
|
+
end
|
|
44
|
+
```
|
|
45
|
+
Ensure you have the rackup gem installed and run:
|
|
46
|
+
```bash
|
|
47
|
+
rackup
|
|
48
|
+
```
|
|
32
49
|
|
|
33
50
|
## Contributing
|
|
34
51
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/devguilhermeribeiiro/eredor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/devguilhermeribeiiro/eredor/blob/master/CODE_OF_CONDUCT.md).
|
|
36
53
|
|
|
37
54
|
## License
|
|
38
55
|
|
|
@@ -40,4 +57,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
40
57
|
|
|
41
58
|
## Code of Conduct
|
|
42
59
|
|
|
43
|
-
Everyone interacting in the Eredor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
|
60
|
+
Everyone interacting in the Eredor project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/devguilhermeribeiiro/eredor/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/eredor/version.rb
CHANGED
data/lib/eredor.rb
CHANGED
|
@@ -47,7 +47,7 @@ module Eredor
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
49
|
def register_route(method, path, &block)
|
|
50
|
-
raise(StandardError,
|
|
50
|
+
raise(StandardError, "A block must be given") unless block_given?
|
|
51
51
|
|
|
52
52
|
keys = []
|
|
53
53
|
regex_path = path.gsub(/:(\w+)/) do |match|
|
|
@@ -79,14 +79,41 @@ module Eredor
|
|
|
79
79
|
# Permitir retorno flexível
|
|
80
80
|
case result
|
|
81
81
|
when Array || Rack::Response then result # já está no formato [status, headers, body]
|
|
82
|
-
when String then [200, {
|
|
82
|
+
when String then [200, { "content-type" => "text/html" }, [result]]
|
|
83
83
|
else
|
|
84
|
-
[500, {
|
|
84
|
+
[500, { "content-type" => "text/plain" }, ["Internal Server Error"]]
|
|
85
85
|
end
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
def not_found
|
|
89
|
-
[404, {
|
|
89
|
+
[404, { "content-type" => "text/plain" }, ["Not Found"]]
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
class BaseController
|
|
94
|
+
attr_reader :params, :request
|
|
95
|
+
|
|
96
|
+
def initialize(request)
|
|
97
|
+
@params = request.params
|
|
98
|
+
@request = request
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def render(file)
|
|
102
|
+
content = get_view(file)
|
|
103
|
+
template = ERB.new(content)
|
|
104
|
+
template.result(binding)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
private
|
|
108
|
+
|
|
109
|
+
def get_view(file)
|
|
110
|
+
File.read("../views/#{controller_name}/#{file}.html.erb")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def controller_name
|
|
114
|
+
controller = self.class.name
|
|
115
|
+
controller.gsub!(/Controller/, "")
|
|
116
|
+
controller.downcase!
|
|
90
117
|
end
|
|
91
118
|
end
|
|
92
119
|
end
|