liberty 0.2.1 → 0.3.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 +4 -4
- data/.qlty/.gitignore +7 -0
- data/.qlty/qlty.toml +81 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +43 -1
- data/Gemfile +5 -4
- data/Gemfile.lock +79 -61
- data/README.md +34 -11
- data/Rakefile +22 -1
- data/lib/liberty/adapters/request.rb +9 -2
- data/lib/liberty/adapters/response.rb +12 -4
- data/lib/liberty/cors/middleware.rb +2 -2
- data/lib/liberty/router.rb +16 -2
- data/lib/liberty/version.rb +1 -1
- data/liberty.gemspec +4 -11
- metadata +13 -97
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 44e1f59a2b827b9bda2ec873fca9e2592db73e23d9ad946ee673be3cca0c8d37
|
|
4
|
+
data.tar.gz: 8ed828dddae3cc7fbce9957bce6d66a11801f13499761728ca03befd954655cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77a90f8920aef4886192435fecc60c46bdb317405ff447db995b9fd264136bd996c6b3b1123c502b7ad375addc8c2756a6dcecfeccdd3bf573b67b54e4d62703
|
|
7
|
+
data.tar.gz: 7891e701f9c931e6e43488e2b45bdd47eb0790e4b8fd098aeb7870386460db43d36357768f1010bac54e819530bdad99dc7e26147e92e351af24a0cbb7b2ad84
|
data/.qlty/.gitignore
ADDED
data/.qlty/qlty.toml
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# This file was automatically generated by `qlty init`.
|
|
2
|
+
# You can modify it to suit your needs.
|
|
3
|
+
# We recommend you to commit this file to your repository.
|
|
4
|
+
#
|
|
5
|
+
# This configuration is used by both Qlty CLI and Qlty Cloud.
|
|
6
|
+
#
|
|
7
|
+
# Qlty CLI -- Code quality toolkit for developers
|
|
8
|
+
# Qlty Cloud -- Fully automated Code Health Platform
|
|
9
|
+
#
|
|
10
|
+
# Try Qlty Cloud: https://qlty.sh
|
|
11
|
+
#
|
|
12
|
+
# For a guide to configuration, visit https://qlty.sh/d/config
|
|
13
|
+
# Or for a full reference, visit https://qlty.sh/d/qlty-toml
|
|
14
|
+
config_version = "0"
|
|
15
|
+
|
|
16
|
+
exclude_patterns = [
|
|
17
|
+
"*_min.*",
|
|
18
|
+
"*-min.*",
|
|
19
|
+
"*.min.*",
|
|
20
|
+
"**/.yarn/**",
|
|
21
|
+
"**/*.d.ts",
|
|
22
|
+
"**/assets/**",
|
|
23
|
+
"**/bower_components/**",
|
|
24
|
+
"**/build/**",
|
|
25
|
+
"**/cache/**",
|
|
26
|
+
"**/config/**",
|
|
27
|
+
"**/db/**",
|
|
28
|
+
"**/deps/**",
|
|
29
|
+
"**/dist/**",
|
|
30
|
+
"**/extern/**",
|
|
31
|
+
"**/external/**",
|
|
32
|
+
"**/generated/**",
|
|
33
|
+
"**/Godeps/**",
|
|
34
|
+
"**/gradlew/**",
|
|
35
|
+
"**/mvnw/**",
|
|
36
|
+
"**/node_modules/**",
|
|
37
|
+
"**/protos/**",
|
|
38
|
+
"**/seed/**",
|
|
39
|
+
"**/target/**",
|
|
40
|
+
"**/templates/**",
|
|
41
|
+
"**/testdata/**",
|
|
42
|
+
"**/vendor/**",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
test_patterns = [
|
|
46
|
+
"**/test/**",
|
|
47
|
+
"**/spec/**",
|
|
48
|
+
"**/*.test.*",
|
|
49
|
+
"**/*.spec.*",
|
|
50
|
+
"**/*_test.*",
|
|
51
|
+
"**/*_spec.*",
|
|
52
|
+
"**/test_*.*",
|
|
53
|
+
"**/spec_*.*",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
[smells]
|
|
57
|
+
mode = "comment"
|
|
58
|
+
|
|
59
|
+
[[source]]
|
|
60
|
+
name = "default"
|
|
61
|
+
default = true
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
[[plugin]]
|
|
65
|
+
name = "actionlint"
|
|
66
|
+
|
|
67
|
+
[[plugin]]
|
|
68
|
+
name = "osv-scanner"
|
|
69
|
+
|
|
70
|
+
[[plugin]]
|
|
71
|
+
name = "ripgrep"
|
|
72
|
+
mode = "comment"
|
|
73
|
+
|
|
74
|
+
[[plugin]]
|
|
75
|
+
name = "standardrb"
|
|
76
|
+
|
|
77
|
+
[[plugin]]
|
|
78
|
+
name = "trufflehog"
|
|
79
|
+
|
|
80
|
+
[[plugin]]
|
|
81
|
+
name = "zizmor"
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,46 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [0.3.1] - 2026-09-07
|
|
2
|
+
|
|
3
|
+
### Fixed
|
|
4
|
+
|
|
5
|
+
- Responds to `HEAD` requests with an empty body, as the Rack specification requires. Status and headers, including `content-length`, still describe what the matching `GET` would return.
|
|
6
|
+
- Responds to `HEAD` requests for unknown routes with a 404 and an empty body.
|
|
7
|
+
- Builds the 404 response per request instead of reusing a frozen constant, which Rack::Lint rejects.
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- Adds `qlty` and `flog` tasks to the default Rake task, alongside `spec` and `standard`.
|
|
12
|
+
|
|
13
|
+
## [0.3.0] - 2026-09-06
|
|
14
|
+
|
|
15
|
+
### Breaking changes
|
|
16
|
+
|
|
17
|
+
- Requires Ruby 3.3 or newer (previously 3.1). Ruby 3.1 and 3.2 are past end of life, and the updated dependencies no longer support them.
|
|
18
|
+
- Requires Rack 3.1 or newer (previously 2.2). Response headers are now emitted in lowercase (`content-type`, `content-length`), as Rack 3 requires. Applications that read Liberty's response headers by their capitalized names should switch to lowercase.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
|
|
22
|
+
- Handles requests with no `rack.input`, which Rack 3.1 made optional. Previously a bodiless request raised `NoMethodError`.
|
|
23
|
+
- Only rewinds the request body when it supports `rewind`, since Rack 3 no longer guarantees a rewindable input.
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Updates mustermann and mustermann-contrib to 4.x.
|
|
28
|
+
- Pins runtime dependencies with pessimistic version constraints.
|
|
29
|
+
- Moves development dependencies from the gemspec to the Gemfile.
|
|
30
|
+
- Enables SimpleCov branch coverage and enforces 100% line and branch coverage in CI.
|
|
31
|
+
- Tests against Ruby 3.3, 3.4, and 4.0 in CI.
|
|
32
|
+
|
|
33
|
+
### Removed
|
|
34
|
+
|
|
35
|
+
- Removes the Code Climate integration and badges. Code Climate Quality has shut down.
|
|
36
|
+
|
|
37
|
+
## [0.2.1] - 2022-04-30
|
|
38
|
+
|
|
39
|
+
- Handles situation where CORS headers are nil
|
|
40
|
+
|
|
41
|
+
## [0.2.0] - 2022-04-27
|
|
42
|
+
|
|
43
|
+
- Adds ability to add your own Rack middleware
|
|
2
44
|
|
|
3
45
|
## [0.1.1] - 2022-04-24
|
|
4
46
|
|
data/Gemfile
CHANGED
|
@@ -5,8 +5,9 @@ source "https://rubygems.org"
|
|
|
5
5
|
# Specify your gem's dependencies in liberty.gemspec
|
|
6
6
|
gemspec
|
|
7
7
|
|
|
8
|
+
gem "flog"
|
|
8
9
|
gem "rake", "~> 13.0"
|
|
9
|
-
|
|
10
|
-
gem "
|
|
11
|
-
|
|
12
|
-
gem "standard", "~> 1.
|
|
10
|
+
gem "rspec", "~> 3.13"
|
|
11
|
+
gem "rspec_junit_formatter", "~> 0.6"
|
|
12
|
+
gem "simplecov", "~> 1.0"
|
|
13
|
+
gem "standard", "~> 1.0"
|
data/Gemfile.lock
CHANGED
|
@@ -1,91 +1,109 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
liberty (0.
|
|
4
|
+
liberty (0.3.1)
|
|
5
5
|
json (~> 2.3)
|
|
6
|
-
mustermann (~>
|
|
7
|
-
mustermann-contrib (~>
|
|
8
|
-
rack (~>
|
|
6
|
+
mustermann (~> 4.0)
|
|
7
|
+
mustermann-contrib (~> 4.0)
|
|
8
|
+
rack (~> 3.1)
|
|
9
9
|
rack-abstract-format (~> 0.9.9)
|
|
10
10
|
rack-accept-media-types (~> 0.9)
|
|
11
11
|
|
|
12
12
|
GEM
|
|
13
13
|
remote: https://rubygems.org/
|
|
14
14
|
specs:
|
|
15
|
-
ast (2.4.
|
|
16
|
-
diff-lcs (1.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
ast (2.4.3)
|
|
16
|
+
diff-lcs (1.6.2)
|
|
17
|
+
flog (4.9.4)
|
|
18
|
+
path_expander (~> 2.0)
|
|
19
|
+
prism (~> 1.7)
|
|
20
|
+
sexp_processor (~> 4.8)
|
|
21
|
+
hansi (0.2.1)
|
|
22
|
+
json (2.21.2)
|
|
23
|
+
language_server-protocol (3.17.0.6)
|
|
24
|
+
lint_roller (1.1.0)
|
|
25
|
+
mustermann (4.0.0)
|
|
26
|
+
mustermann-contrib (4.0.0)
|
|
23
27
|
hansi (~> 0.2.0)
|
|
24
|
-
mustermann (=
|
|
25
|
-
parallel (
|
|
26
|
-
parser (3.
|
|
28
|
+
mustermann (= 4.0.0)
|
|
29
|
+
parallel (2.2.0)
|
|
30
|
+
parser (3.3.12.0)
|
|
27
31
|
ast (~> 2.4.1)
|
|
28
|
-
|
|
32
|
+
racc
|
|
33
|
+
path_expander (2.0.1)
|
|
34
|
+
prism (1.9.0)
|
|
35
|
+
racc (1.8.1)
|
|
36
|
+
rack (3.2.7)
|
|
29
37
|
rack-abstract-format (0.9.9)
|
|
30
38
|
rack-accept-media-types (0.9)
|
|
31
39
|
rainbow (3.1.1)
|
|
32
|
-
rake (13.
|
|
33
|
-
regexp_parser (2.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
rspec-
|
|
37
|
-
rspec-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
rspec-expectations (3.11.0)
|
|
40
|
+
rake (13.4.2)
|
|
41
|
+
regexp_parser (2.12.0)
|
|
42
|
+
rspec (3.13.2)
|
|
43
|
+
rspec-core (~> 3.13.0)
|
|
44
|
+
rspec-expectations (~> 3.13.0)
|
|
45
|
+
rspec-mocks (~> 3.13.0)
|
|
46
|
+
rspec-core (3.13.6)
|
|
47
|
+
rspec-support (~> 3.13.0)
|
|
48
|
+
rspec-expectations (3.13.5)
|
|
42
49
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
-
rspec-support (~> 3.
|
|
44
|
-
rspec-mocks (3.
|
|
50
|
+
rspec-support (~> 3.13.0)
|
|
51
|
+
rspec-mocks (3.13.8)
|
|
45
52
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
46
|
-
rspec-support (~> 3.
|
|
47
|
-
rspec-support (3.
|
|
48
|
-
rspec_junit_formatter (0.
|
|
53
|
+
rspec-support (~> 3.13.0)
|
|
54
|
+
rspec-support (3.13.7)
|
|
55
|
+
rspec_junit_formatter (0.6.0)
|
|
49
56
|
rspec-core (>= 2, < 4, != 2.12.0)
|
|
50
|
-
rubocop (1.
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
rubocop (1.88.2)
|
|
58
|
+
json (~> 2.3)
|
|
59
|
+
language_server-protocol (~> 3.17.0.2)
|
|
60
|
+
lint_roller (~> 1.1.0)
|
|
61
|
+
parallel (>= 1.10)
|
|
62
|
+
parser (>= 3.3.0.2)
|
|
53
63
|
rainbow (>= 2.2.2, < 4.0)
|
|
54
|
-
regexp_parser (>=
|
|
55
|
-
|
|
56
|
-
rubocop-ast (>= 1.16.0, < 2.0)
|
|
64
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
65
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
57
66
|
ruby-progressbar (~> 1.7)
|
|
58
|
-
unicode-display_width (>=
|
|
59
|
-
rubocop-ast (1.
|
|
60
|
-
parser (>= 3.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
rubocop (
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
68
|
+
rubocop-ast (1.50.0)
|
|
69
|
+
parser (>= 3.3.7.2)
|
|
70
|
+
prism (~> 1.7)
|
|
71
|
+
rubocop-performance (1.26.1)
|
|
72
|
+
lint_roller (~> 1.1)
|
|
73
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
74
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
75
|
+
ruby-progressbar (1.13.0)
|
|
76
|
+
sexp_processor (4.17.5)
|
|
77
|
+
simplecov (1.2.0)
|
|
78
|
+
standard (1.56.0)
|
|
79
|
+
language_server-protocol (~> 3.17.0.2)
|
|
80
|
+
lint_roller (~> 1.0)
|
|
81
|
+
rubocop (~> 1.88.0)
|
|
82
|
+
standard-custom (~> 1.0.0)
|
|
83
|
+
standard-performance (~> 1.8)
|
|
84
|
+
standard-custom (1.0.2)
|
|
85
|
+
lint_roller (~> 1.0)
|
|
86
|
+
rubocop (~> 1.50)
|
|
87
|
+
standard-performance (1.9.0)
|
|
88
|
+
lint_roller (~> 1.1)
|
|
89
|
+
rubocop-performance (~> 1.26.0)
|
|
90
|
+
unicode-display_width (3.2.0)
|
|
91
|
+
unicode-emoji (~> 4.1)
|
|
92
|
+
unicode-emoji (4.2.0)
|
|
75
93
|
|
|
76
94
|
PLATFORMS
|
|
95
|
+
arm64-darwin-23
|
|
77
96
|
x86_64-darwin-21
|
|
78
97
|
x86_64-linux
|
|
79
98
|
|
|
80
99
|
DEPENDENCIES
|
|
81
|
-
|
|
100
|
+
flog
|
|
82
101
|
liberty!
|
|
83
|
-
rack (~> 2.2)
|
|
84
102
|
rake (~> 13.0)
|
|
85
|
-
rspec (~> 3.
|
|
86
|
-
rspec_junit_formatter (~> 0.
|
|
87
|
-
simplecov (~> 0
|
|
88
|
-
standard (~> 1.
|
|
103
|
+
rspec (~> 3.13)
|
|
104
|
+
rspec_junit_formatter (~> 0.6)
|
|
105
|
+
simplecov (~> 1.0)
|
|
106
|
+
standard (~> 1.0)
|
|
89
107
|
|
|
90
108
|
BUNDLED WITH
|
|
91
|
-
2.
|
|
109
|
+
2.6.9
|
data/README.md
CHANGED
|
@@ -2,25 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
# Liberty
|
|
4
4
|
|
|
5
|
-
[](https://badge.fury.io/rb/liberty)
|
|
5
|
+
[](https://badge.fury.io/rb/liberty)
|
|
6
|
+
[](https://github.com/first-try-software/liberty/actions/workflows/main.yml)
|
|
6
7
|
|
|
7
8
|
Liberty is the state of being free from oppressive restrictions imposed by authority.
|
|
8
9
|
|
|
9
|
-
Liberty is also a minimalist web-framework for Ruby that seeks to get out of your way
|
|
10
|
-
so that you can focus on your most valuable asset: your business logic. It is structured
|
|
11
|
-
in a way that encourages you to separate your business logic from the framework code.
|
|
12
|
-
It provides the web adapter for a Hexagonal Architecture and it works well with Domain
|
|
13
|
-
Driven Design.
|
|
10
|
+
Liberty is also a minimalist web-framework for Ruby that seeks to get out of your way so that you can focus on your most valuable asset — the part of your application that is uniquely yours — your business logic.
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
Liberty is structured in a way that encourages you to separate your business logic from the underlying framework code. It provides a web adapter for a Hexagonal Architecture, and it works very well with Domain Driven Design.
|
|
16
13
|
|
|
17
|
-
|
|
14
|
+
Though Liberty does not shackle you to convention, we (the authors) do consider there to be some best practices:
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
First, we believe THE most important aspect of your software is your domain logic. As such, we believe you should start there, and spend the vast majority of your time working on that code. Tests can act as the front-end to drive your domain logic, and mock repositories can act as your data store. This allows you to develop your business logic in isolation.
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
Second, we believe your application should look uniquely yours inside an editor. Accounting programs should not look like social networks. And, neither should look like a game. As such, we encourage you to put your business logic in an obvious place that is separate and apart from the framework concepts. (We typically use a `domain` folder in which we have folders for each Bounded Context.)
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
Third, we believe the code that ties your application to physical infrastructure, like the web or a database or a messaging system, should be stored somewhere else. (We typically use an `app` folder for this code, with folders for `endpoints`, concrete `repositories`, and other bits of glue code.)
|
|
21
|
+
|
|
22
|
+
A small application for managing to-do lists might look like this:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
todo/
|
|
26
|
+
app/
|
|
27
|
+
endpoints/
|
|
28
|
+
repositories/
|
|
29
|
+
domain/
|
|
30
|
+
todos/
|
|
31
|
+
users/
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The `/app` folder contains the code that glues the domain logic to the outside world. While the `domain` folder contains the DDD Bounded Contexts within the application.
|
|
35
|
+
|
|
36
|
+
That said, Liberty does not use convention. It relies on classes declaratively registering themselves at load time to handle a specific use case or web request. The router dispatches requests to the appropriate endpoint (in lightning speed, we might add). And, a dispatcher calls the appropriate use case when needed.
|
|
24
37
|
|
|
25
38
|
## Usage
|
|
26
39
|
|
|
@@ -70,6 +83,16 @@ end
|
|
|
70
83
|
If you configure your CORS headers before you launch your application, `Endpoints` will
|
|
71
84
|
automatically respond with the right headers.
|
|
72
85
|
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
89
|
+
|
|
90
|
+
$ bundle add liberty
|
|
91
|
+
|
|
92
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
93
|
+
|
|
94
|
+
$ gem install liberty
|
|
95
|
+
|
|
73
96
|
## Development
|
|
74
97
|
|
|
75
98
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
|
@@ -7,4 +7,25 @@ RSpec::Core::RakeTask.new(:spec)
|
|
|
7
7
|
|
|
8
8
|
require "standard/rake"
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
FLOG_LIMIT = 10.0
|
|
11
|
+
|
|
12
|
+
def qlty_bin
|
|
13
|
+
installed = File.expand_path("~/.qlty/bin/qlty")
|
|
14
|
+
ENV.fetch("QLTY_BIN") { File.exist?(installed) ? installed : "qlty" }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
desc "Run qlty lint checks and report code smells"
|
|
18
|
+
task :qlty do
|
|
19
|
+
sh qlty_bin, "check", "--all", "--no-progress"
|
|
20
|
+
sh qlty_bin, "smells", "--all", "--quiet"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
desc "Fail when the average flog score per method reaches #{FLOG_LIMIT}"
|
|
24
|
+
task :flog do
|
|
25
|
+
report = `bundle exec flog -m lib`
|
|
26
|
+
puts report
|
|
27
|
+
average = report[/^\s*([\d.]+): flog\/method average/, 1].to_f
|
|
28
|
+
abort("Quality gate failed: average flog #{average} is #{FLOG_LIMIT} or higher") if average >= FLOG_LIMIT
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
task default: %i[spec standard qlty flog]
|
|
@@ -25,6 +25,10 @@ module Liberty
|
|
|
25
25
|
@params ||= env ? all_params : {}
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
def head?
|
|
29
|
+
env ? rack_request.head? : false
|
|
30
|
+
end
|
|
31
|
+
|
|
28
32
|
private
|
|
29
33
|
|
|
30
34
|
def all_params
|
|
@@ -52,8 +56,11 @@ module Liberty
|
|
|
52
56
|
end
|
|
53
57
|
|
|
54
58
|
def body
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
input = rack_request.body
|
|
60
|
+
return nil unless input
|
|
61
|
+
|
|
62
|
+
read_body = input.read
|
|
63
|
+
input.rewind if input.respond_to?(:rewind)
|
|
57
64
|
read_body
|
|
58
65
|
end
|
|
59
66
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
module Liberty
|
|
4
4
|
module Adapters
|
|
5
5
|
class Response
|
|
6
|
-
CONTENT_TYPE = "
|
|
7
|
-
CONTENT_LENGTH = "
|
|
6
|
+
CONTENT_TYPE = "content-type"
|
|
7
|
+
CONTENT_LENGTH = "content-length"
|
|
8
8
|
MIME_TYPE_JSON = "application/json"
|
|
9
9
|
MIME_TYPE_HTML = "text/html"
|
|
10
10
|
MIME_TYPE_TEXT = "text/plain"
|
|
@@ -17,7 +17,7 @@ module Liberty
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def to_rack_response
|
|
20
|
-
[status, headers,
|
|
20
|
+
[status, headers, rack_body]
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
private
|
|
@@ -26,6 +26,14 @@ module Liberty
|
|
|
26
26
|
endpoint.status
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
+
def rack_body
|
|
30
|
+
head? ? [] : [content]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def head?
|
|
34
|
+
endpoint.request.head?
|
|
35
|
+
end
|
|
36
|
+
|
|
29
37
|
def headers
|
|
30
38
|
headers = {CONTENT_LENGTH => content_length}
|
|
31
39
|
headers[CONTENT_TYPE] = content_type if content_type
|
|
@@ -40,7 +48,7 @@ module Liberty
|
|
|
40
48
|
def content_type
|
|
41
49
|
return MIME_TYPE_JSON if json
|
|
42
50
|
return MIME_TYPE_HTML if html
|
|
43
|
-
|
|
51
|
+
MIME_TYPE_TEXT if text
|
|
44
52
|
end
|
|
45
53
|
|
|
46
54
|
def content_length
|
data/lib/liberty/router.rb
CHANGED
|
@@ -15,7 +15,9 @@ module Liberty
|
|
|
15
15
|
PATH_INFO = "PATH_INFO"
|
|
16
16
|
ROUTER_PARAMS = "router.params"
|
|
17
17
|
DYNAMIC_PREFIX = /:/
|
|
18
|
-
|
|
18
|
+
NOT_FOUND_STATUS = 404
|
|
19
|
+
NOT_FOUND_BODY = "Not Found"
|
|
20
|
+
CONTENT_LENGTH = "content-length"
|
|
19
21
|
|
|
20
22
|
def initialize
|
|
21
23
|
@apps = {}
|
|
@@ -46,7 +48,7 @@ module Liberty
|
|
|
46
48
|
|
|
47
49
|
def call(env)
|
|
48
50
|
endpoint = find_endpoint(env[REQUEST_METHOD], env[PATH_INFO]) { |params| env[ROUTER_PARAMS] = params }
|
|
49
|
-
endpoint ? endpoint.call(env) :
|
|
51
|
+
endpoint ? endpoint.call(env) : not_found_response(env)
|
|
50
52
|
end
|
|
51
53
|
|
|
52
54
|
def print(stdout = $stdout)
|
|
@@ -55,6 +57,18 @@ module Liberty
|
|
|
55
57
|
|
|
56
58
|
private
|
|
57
59
|
|
|
60
|
+
def not_found_response(env)
|
|
61
|
+
[NOT_FOUND_STATUS, not_found_headers, not_found_body(env)]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def not_found_headers
|
|
65
|
+
{CONTENT_LENGTH => NOT_FOUND_BODY.bytesize.to_s}
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def not_found_body(env)
|
|
69
|
+
(env[REQUEST_METHOD] == HEAD) ? [] : [NOT_FOUND_BODY]
|
|
70
|
+
end
|
|
71
|
+
|
|
58
72
|
def register_route(verb, path, to)
|
|
59
73
|
dynamic?(path) ? register_dynamic_route(verb, path, to) : register_static_route(verb, path, to)
|
|
60
74
|
end
|
data/lib/liberty/version.rb
CHANGED
data/liberty.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = "Liberty is the state of being free from oppressive restrictions imposed by authority."
|
|
13
13
|
spec.homepage = "https://github.com/first-try-software/liberty"
|
|
14
14
|
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = ">= 3.
|
|
15
|
+
spec.required_ruby_version = ">= 3.3.0"
|
|
16
16
|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
18
|
spec.metadata["source_code_uri"] = spec.homepage
|
|
@@ -28,16 +28,9 @@ Gem::Specification.new do |spec|
|
|
|
28
28
|
spec.require_paths = ["lib"]
|
|
29
29
|
|
|
30
30
|
spec.add_dependency "json", "~> 2.3"
|
|
31
|
-
spec.add_dependency "mustermann", "~>
|
|
32
|
-
spec.add_dependency "mustermann-contrib", "~>
|
|
33
|
-
spec.add_dependency "rack", "~>
|
|
31
|
+
spec.add_dependency "mustermann", "~> 4.0"
|
|
32
|
+
spec.add_dependency "mustermann-contrib", "~> 4.0"
|
|
33
|
+
spec.add_dependency "rack", "~> 3.1"
|
|
34
34
|
spec.add_dependency "rack-abstract-format", "~> 0.9.9"
|
|
35
35
|
spec.add_dependency "rack-accept-media-types", "~> 0.9"
|
|
36
|
-
|
|
37
|
-
spec.add_development_dependency "bundler", "~> 2.0"
|
|
38
|
-
spec.add_development_dependency "rack", "~> 2.2"
|
|
39
|
-
spec.add_development_dependency "rake", "~> 12.0"
|
|
40
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
|
41
|
-
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4"
|
|
42
|
-
spec.add_development_dependency "simplecov", "~> 0.17.1"
|
|
43
36
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: liberty
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alan Ridlehoover
|
|
8
8
|
- Fito von Zastrow
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: json
|
|
@@ -31,42 +30,42 @@ dependencies:
|
|
|
31
30
|
requirements:
|
|
32
31
|
- - "~>"
|
|
33
32
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '
|
|
33
|
+
version: '4.0'
|
|
35
34
|
type: :runtime
|
|
36
35
|
prerelease: false
|
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
37
|
requirements:
|
|
39
38
|
- - "~>"
|
|
40
39
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '
|
|
40
|
+
version: '4.0'
|
|
42
41
|
- !ruby/object:Gem::Dependency
|
|
43
42
|
name: mustermann-contrib
|
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
|
45
44
|
requirements:
|
|
46
45
|
- - "~>"
|
|
47
46
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '
|
|
47
|
+
version: '4.0'
|
|
49
48
|
type: :runtime
|
|
50
49
|
prerelease: false
|
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
51
|
requirements:
|
|
53
52
|
- - "~>"
|
|
54
53
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '
|
|
54
|
+
version: '4.0'
|
|
56
55
|
- !ruby/object:Gem::Dependency
|
|
57
56
|
name: rack
|
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
|
59
58
|
requirements:
|
|
60
59
|
- - "~>"
|
|
61
60
|
- !ruby/object:Gem::Version
|
|
62
|
-
version: '
|
|
61
|
+
version: '3.1'
|
|
63
62
|
type: :runtime
|
|
64
63
|
prerelease: false
|
|
65
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
66
65
|
requirements:
|
|
67
66
|
- - "~>"
|
|
68
67
|
- !ruby/object:Gem::Version
|
|
69
|
-
version: '
|
|
68
|
+
version: '3.1'
|
|
70
69
|
- !ruby/object:Gem::Dependency
|
|
71
70
|
name: rack-abstract-format
|
|
72
71
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -95,90 +94,6 @@ dependencies:
|
|
|
95
94
|
- - "~>"
|
|
96
95
|
- !ruby/object:Gem::Version
|
|
97
96
|
version: '0.9'
|
|
98
|
-
- !ruby/object:Gem::Dependency
|
|
99
|
-
name: bundler
|
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
|
101
|
-
requirements:
|
|
102
|
-
- - "~>"
|
|
103
|
-
- !ruby/object:Gem::Version
|
|
104
|
-
version: '2.0'
|
|
105
|
-
type: :development
|
|
106
|
-
prerelease: false
|
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
-
requirements:
|
|
109
|
-
- - "~>"
|
|
110
|
-
- !ruby/object:Gem::Version
|
|
111
|
-
version: '2.0'
|
|
112
|
-
- !ruby/object:Gem::Dependency
|
|
113
|
-
name: rack
|
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
|
115
|
-
requirements:
|
|
116
|
-
- - "~>"
|
|
117
|
-
- !ruby/object:Gem::Version
|
|
118
|
-
version: '2.2'
|
|
119
|
-
type: :development
|
|
120
|
-
prerelease: false
|
|
121
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
122
|
-
requirements:
|
|
123
|
-
- - "~>"
|
|
124
|
-
- !ruby/object:Gem::Version
|
|
125
|
-
version: '2.2'
|
|
126
|
-
- !ruby/object:Gem::Dependency
|
|
127
|
-
name: rake
|
|
128
|
-
requirement: !ruby/object:Gem::Requirement
|
|
129
|
-
requirements:
|
|
130
|
-
- - "~>"
|
|
131
|
-
- !ruby/object:Gem::Version
|
|
132
|
-
version: '12.0'
|
|
133
|
-
type: :development
|
|
134
|
-
prerelease: false
|
|
135
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
136
|
-
requirements:
|
|
137
|
-
- - "~>"
|
|
138
|
-
- !ruby/object:Gem::Version
|
|
139
|
-
version: '12.0'
|
|
140
|
-
- !ruby/object:Gem::Dependency
|
|
141
|
-
name: rspec
|
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
|
143
|
-
requirements:
|
|
144
|
-
- - "~>"
|
|
145
|
-
- !ruby/object:Gem::Version
|
|
146
|
-
version: '3.0'
|
|
147
|
-
type: :development
|
|
148
|
-
prerelease: false
|
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
150
|
-
requirements:
|
|
151
|
-
- - "~>"
|
|
152
|
-
- !ruby/object:Gem::Version
|
|
153
|
-
version: '3.0'
|
|
154
|
-
- !ruby/object:Gem::Dependency
|
|
155
|
-
name: rspec_junit_formatter
|
|
156
|
-
requirement: !ruby/object:Gem::Requirement
|
|
157
|
-
requirements:
|
|
158
|
-
- - "~>"
|
|
159
|
-
- !ruby/object:Gem::Version
|
|
160
|
-
version: '0.4'
|
|
161
|
-
type: :development
|
|
162
|
-
prerelease: false
|
|
163
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
164
|
-
requirements:
|
|
165
|
-
- - "~>"
|
|
166
|
-
- !ruby/object:Gem::Version
|
|
167
|
-
version: '0.4'
|
|
168
|
-
- !ruby/object:Gem::Dependency
|
|
169
|
-
name: simplecov
|
|
170
|
-
requirement: !ruby/object:Gem::Requirement
|
|
171
|
-
requirements:
|
|
172
|
-
- - "~>"
|
|
173
|
-
- !ruby/object:Gem::Version
|
|
174
|
-
version: 0.17.1
|
|
175
|
-
type: :development
|
|
176
|
-
prerelease: false
|
|
177
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
178
|
-
requirements:
|
|
179
|
-
- - "~>"
|
|
180
|
-
- !ruby/object:Gem::Version
|
|
181
|
-
version: 0.17.1
|
|
182
97
|
description: Liberty is the state of being free from oppressive restrictions imposed
|
|
183
98
|
by authority.
|
|
184
99
|
email:
|
|
@@ -187,7 +102,10 @@ executables: []
|
|
|
187
102
|
extensions: []
|
|
188
103
|
extra_rdoc_files: []
|
|
189
104
|
files:
|
|
105
|
+
- ".qlty/.gitignore"
|
|
106
|
+
- ".qlty/qlty.toml"
|
|
190
107
|
- ".rspec"
|
|
108
|
+
- ".ruby-version"
|
|
191
109
|
- ".standard.yml"
|
|
192
110
|
- CHANGELOG.md
|
|
193
111
|
- CODE_OF_CONDUCT.md
|
|
@@ -220,7 +138,6 @@ metadata:
|
|
|
220
138
|
homepage_uri: https://github.com/first-try-software/liberty
|
|
221
139
|
source_code_uri: https://github.com/first-try-software/liberty
|
|
222
140
|
changelog_uri: https://github.com/first-try-software/liberty/CHANGELOG.md
|
|
223
|
-
post_install_message:
|
|
224
141
|
rdoc_options: []
|
|
225
142
|
require_paths:
|
|
226
143
|
- lib
|
|
@@ -228,15 +145,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
228
145
|
requirements:
|
|
229
146
|
- - ">="
|
|
230
147
|
- !ruby/object:Gem::Version
|
|
231
|
-
version: 3.
|
|
148
|
+
version: 3.3.0
|
|
232
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
150
|
requirements:
|
|
234
151
|
- - ">="
|
|
235
152
|
- !ruby/object:Gem::Version
|
|
236
153
|
version: '0'
|
|
237
154
|
requirements: []
|
|
238
|
-
rubygems_version:
|
|
239
|
-
signing_key:
|
|
155
|
+
rubygems_version: 4.0.16
|
|
240
156
|
specification_version: 4
|
|
241
157
|
summary: A framework for Ruby web applications
|
|
242
158
|
test_files: []
|