guaraci 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 872f02c23c21487409ca93acc9c6fb36fd25d54f8a03f0c6ffe502f9b36e61a6
4
+ data.tar.gz: 42e120be9876e28afdec28d8673287d927d8a9a4fbff3011fec36ccd08c98b84
5
+ SHA512:
6
+ metadata.gz: b8c423cb5d52ebd4420ca37959bd0b0e147b238ddc2882e5145664b29059cc10fdf5908f61e8928500ceb94707873aaba1d9d6aa7779a433e32f70d3f948152c
7
+ data.tar.gz: d9404e2dd3929e1b2c950f37412b495a9a0d61b77801c33de8b4b3e718aa72561b8b100dd49f49f472fed908d32cc3fba7ebacb8770a178e740efcd5a5d3258b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-08-01
4
+
5
+ - Initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Guilherme Silva
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Guaraci
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
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/guaraci`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
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.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/guaraci.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal
2
+
3
+ require 'json'
4
+
5
+ module Guaraci
6
+ class Request
7
+ attr_reader :method, :path_segments, :raw_request
8
+
9
+ def initialize(raw_request)
10
+ @method = raw_request.method
11
+ @path_segments = raw_request.path.split('/').reject(&:empty?)
12
+ @raw_request = raw_request
13
+ end
14
+
15
+ def body
16
+ @body ||= raw_request.read
17
+ end
18
+
19
+ def params
20
+ JSON.parse(body)
21
+ rescue JSON::ParseError
22
+ {}
23
+ end
24
+
25
+ def headers = raw_request.headers
26
+
27
+ def query
28
+ raw_request.query || ""
29
+ end
30
+
31
+ def query_params
32
+ @query_params ||= parse_query
33
+ end
34
+
35
+ private
36
+
37
+ def parse_query
38
+ query.split('&').map { |q| q.split('=') }.to_a
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Guaraci
6
+ class Response
7
+ attr_reader :status, :body, :headers
8
+
9
+ def initialize(status)
10
+ @status = status
11
+ @headers = {}
12
+ @body = []
13
+ end
14
+
15
+ def self.ok
16
+ res = new(200)
17
+ yield(res) if block_given?
18
+ res
19
+ end
20
+
21
+ def json(object)
22
+ @headers["Content-Type"] = "application/json"
23
+ @body = [JSON.dump((object))]
24
+ end
25
+
26
+ def to_a
27
+ [@status, @headers, @body]
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './request.rb'
4
+ require "async"
5
+ require "async/http/server"
6
+ require "async/http/endpoint"
7
+ require "async/http/protocol/http1"
8
+ require "json"
9
+
10
+ module Guaraci
11
+ class Server
12
+ def initialize(&block)
13
+ @handler = block
14
+ end
15
+
16
+ def call(request)
17
+ request = Request.new(request)
18
+
19
+ instance_exec(request, &@handler)
20
+ end
21
+
22
+ def self.run(host: 'localhost', port: 8000, &block)
23
+ app = new(&block)
24
+ url = "http://#{host}:#{port}"
25
+
26
+ Async do
27
+ endpoint = Async::HTTP::Endpoint.parse(url)
28
+ server = Async::HTTP::Server.new(app.method(:call), endpoint, protocol: Async::HTTP::Protocol::HTTP1)
29
+
30
+ puts "Guaraci running on #{url}"
31
+ server.run
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Guaraci
4
+ VERSION = "0.1.0"
5
+ end
data/lib/guaraci.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./guaraci/server"
4
+ require_relative "./guaraci/response"
5
+ require_relative "./guaraci/request"
6
+
7
+ module Guaraci
8
+ end
data/sig/guaraci.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Guaraci
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guaraci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Guilherme Silva
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: async
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: 2.27.0
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: 2.27.0
26
+ - !ruby/object:Gem::Dependency
27
+ name: async-http
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.89.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: 0.89.0
40
+ - !ruby/object:Gem::Dependency
41
+ name: json
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ description: A very simple web framework made with async http
55
+ email:
56
+ - guilherme.gss@outlook.com.br
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - CHANGELOG.md
62
+ - LICENSE.txt
63
+ - README.md
64
+ - Rakefile
65
+ - lib/guaraci.rb
66
+ - lib/guaraci/request.rb
67
+ - lib/guaraci/response.rb
68
+ - lib/guaraci/server.rb
69
+ - lib/guaraci/version.rb
70
+ - sig/guaraci.rbs
71
+ homepage: https://github.com/glmsilva/guaraci
72
+ licenses:
73
+ - MIT
74
+ metadata:
75
+ source_code_uri: https://github.com/glmsilva/guaraci
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 3.2.0
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.7.1
91
+ specification_version: 4
92
+ summary: Guaraci ruby web microframework
93
+ test_files: []