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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -16
  3. data/lib/eredor/version.rb +1 -1
  4. data/lib/eredor.rb +31 -4
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49c19000db63cb02454327189e781e1e0329a5d7eee156cb3b92399b3d51961a
4
- data.tar.gz: 596d2f66edf7dfa31ae3230232aae2a281e3d6b24dec91faafddce08667371ed
3
+ metadata.gz: '07877c607d2d4cd1c6ad3bf504d48f8cc19c70bd6cfacfe344dd17ac2d479796'
4
+ data.tar.gz: cee85827f625435e7e93a205c3ba50403ca68cdb8794fb49bb5f5bf72051ff63
5
5
  SHA512:
6
- metadata.gz: 98a9e1b1aead447f706bf0861f33138790cf4bb1c98862fa6002d82f57a9d6897baf99594f82a20d202a79154d3e5a18eb88e445e86f9054f638ef0ae2381768
7
- data.tar.gz: af4dc482d81d57055f8b8bf817e8bae29dd1350762e5817ce8b9a3fe3a62182dc9404a2aef235f9c8b3ed085c8022c6ab93e26a203adef74650753540cd6c3ef
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/eredor`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ [![Gem Version](https://badge.fury.io/rb/eredor.svg)](https://rubygems.org/gems/eredor)
5
+ [![Downloads](https://badgen.net/rubygems/dt/eredor)](https://rubygems.org/gems/eredor)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
7
+ [![GitHub Repo stars](https://img.shields.io/github/stars/devguilhermeribeiiro/eredor?style=social)](https://github.com/devguilhermeribeiiro/eredor)
6
8
 
7
- ## Installation
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
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
11
+ ---
12
+ ## ⚡ **Instalation**
10
13
 
11
- Install the gem and add to the application's Gemfile by executing:
14
+ Install via [RubyGems.org](https://rubygems.org/gems/eredor):
12
15
 
13
16
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
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
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
22
+ bundle add eredor
23
+ bundle install
21
24
  ```
22
25
 
23
26
  ## Usage
24
27
 
25
- TODO: Write usage instructions here
28
+ Add to your config.ru:
29
+
30
+ ```bash
31
+ require 'rack'
32
+ require 'eredor'
26
33
 
27
- ## Development
34
+ run do |env|
35
+ request = Rack::Request.new(env)
36
+ router = Eredor::Router.new(request)
28
37
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
38
+ router.get '/' do
39
+ '<h1>Hello from Eredor</h1>'
40
+ end
30
41
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/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/[USERNAME]/eredor/blob/master/CODE_OF_CONDUCT.md).
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/[USERNAME]/eredor/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eredor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
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, 'A block must be given') unless block_given?
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, { 'content-type' => 'text/html' }, [result]]
82
+ when String then [200, { "content-type" => "text/html" }, [result]]
83
83
  else
84
- [500, { 'content-type' => 'text/plain' }, ['Internal Server Error']]
84
+ [500, { "content-type" => "text/plain" }, ["Internal Server Error"]]
85
85
  end
86
86
  end
87
87
 
88
88
  def not_found
89
- [404, { 'content-type' => 'text/plain' }, ['Not Found']]
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eredor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Ribeiro