brut 0.0.12 → 0.0.13
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/Gemfile.lock +1 -1
- data/lib/brut/front_end/generic_response.rb +33 -0
- data/lib/brut/front_end/handler.rb +2 -0
- data/lib/brut/front_end/request_context.rb +2 -0
- data/lib/brut/sinatra_helpers.rb +2 -0
- data/lib/brut/version.rb +1 -1
- data/lib/brut.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e8b01889cc06839d9cca47e021c8b781e6f21417b08ba0658d55697285bb061
|
4
|
+
data.tar.gz: 4d1bf20dac16e8e6322402aa364f886235140028e53f8aa313ddc6d3b2de81c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77c38b80c31452da7db8ef80ce2532aa1d3193257193d70625135d23af01695cc5f0c3f46568988bcf0c02849af8b8f9f3f166f9065445efd90a160c1e3206c0
|
7
|
+
data.tar.gz: e36fa4f081d48518cf941d0e0323cde04a6370082e0a594da73221f65c1f319d29df29c7cbd5663f30b2da2776fa8ec24295a16cc55b41b94c6f1096590282f7
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# A generic response to use when no built-in Brut construct will suffice.
|
2
|
+
# This mirrors the response a Rack server is intended to produce, and serves
|
3
|
+
# as merely a typed wrapper around that kind of response for the purposes of
|
4
|
+
# understanding the intention of whoever is returning this.
|
5
|
+
#
|
6
|
+
# Once created, {#to_ary} will convert this into the array that Rack requires.
|
7
|
+
class Brut::FrontEnd::GenericResponse
|
8
|
+
# Create a generic response.
|
9
|
+
#
|
10
|
+
# @param [Brut::FrontEnd::HttpStatus|number] http_status the status to send. If omitted, a 200 is used.
|
11
|
+
# Note that this value must be a valid HTTP status.
|
12
|
+
# @param [Hash<String|String>] headers hash of headers to send with the response.
|
13
|
+
# @param [String|Array<String>|IO|Enumerable] response_body the body of the response. This is passed
|
14
|
+
# through directly to the underlying Rack server so it should be whatever Rack expects, which is generally
|
15
|
+
# something that responds to `each`.
|
16
|
+
def initialize(http_status: 200, headers: {}, response_body:)
|
17
|
+
@response_body = response_body
|
18
|
+
@headers = headers
|
19
|
+
@http_status = Brut::FrontEnd::HttpStatus.new(http_status.to_i)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return this as an array suitable for use as a Rack response.
|
23
|
+
#
|
24
|
+
# @return [Array{String,3}] the response_body, headers, and http_status
|
25
|
+
def to_ary
|
26
|
+
[
|
27
|
+
@http_status.to_i,
|
28
|
+
@headers,
|
29
|
+
@response_body,
|
30
|
+
]
|
31
|
+
end
|
32
|
+
alias deconstruct to_ary
|
33
|
+
end
|
@@ -19,6 +19,8 @@ module Brut::FrontEnd
|
|
19
19
|
# * Array of two items, with the first being an Instance of {Brut::FrontEnd::Component} and the second being an {Brut::FrontEnd::HttpStatus} - renders that component or page, but responds with the given HTTP status. Useful for Ajax requests that don't return 200, but do return useful content.
|
20
20
|
# * Instance of {Brut::FrontEnd::HttpStatus} - returns just that status code. Typically you would do this by calling {Brut::FrontEnd::HandlingResults#http_status}
|
21
21
|
# * Instance of {Brut::FrontEnd::Download} - sends a file download to the browser.
|
22
|
+
# * Instance of {Brut::FrontEnd::GenericResponse} - sends itself as the rack response. Use this only if
|
23
|
+
# you cannot use one of the other options
|
22
24
|
#
|
23
25
|
# @return [URI|Brut::FrontEnd::Component,Array,Brut::FrontEnd::HttpStatus,Brut::FrontEnd::Download]
|
24
26
|
def handle(**)
|
@@ -177,6 +177,8 @@ private
|
|
177
177
|
args[name] = route
|
178
178
|
elsif !request_params.nil? && (request_params[name.to_s] || request_params[name.to_sym])
|
179
179
|
args[name] = RichString.new(request_params[name.to_s] || request_params[name.to_sym]).to_s_or_nil
|
180
|
+
elsif name == :raw_params
|
181
|
+
args[name] = request_params || {}
|
180
182
|
elsif type == :keyreq
|
181
183
|
request_params_message = if request_params.nil?
|
182
184
|
"no request params provied"
|
data/lib/brut/sinatra_helpers.rb
CHANGED
@@ -203,6 +203,8 @@ module Brut::SinatraHelpers
|
|
203
203
|
http_status.to_i
|
204
204
|
in Brut::FrontEnd::Download => download
|
205
205
|
[ 200, download.headers, download.data ]
|
206
|
+
in Brut::FrontEnd::GenericResponse => response
|
207
|
+
response.to_ary
|
206
208
|
else
|
207
209
|
raise NoMatchingPatternError, "Result from #{handler.class}'s handle! method was a #{result.class}, which cannot be used to understand the response to generate"
|
208
210
|
end
|
data/lib/brut/version.rb
CHANGED
data/lib/brut.rb
CHANGED
@@ -36,6 +36,7 @@ module Brut
|
|
36
36
|
autoload(:HandlingResults, "brut/front_end/handling_results")
|
37
37
|
autoload(:HttpMethod, "brut/front_end/http_method")
|
38
38
|
autoload(:HttpStatus, "brut/front_end/http_status")
|
39
|
+
autoload(:GenericResponse, "brut/front_end/generic_response")
|
39
40
|
autoload(:Middleware, "brut/front_end/middleware")
|
40
41
|
autoload(:Middlewares, "brut/front_end/middleware")
|
41
42
|
autoload(:Page, "brut/front_end/page")
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brut
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Bryant Copeland
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: irb
|
@@ -518,6 +518,7 @@ files:
|
|
518
518
|
- lib/brut/front_end/forms/select_input.rb
|
519
519
|
- lib/brut/front_end/forms/select_input_definition.rb
|
520
520
|
- lib/brut/front_end/forms/validity_state.rb
|
521
|
+
- lib/brut/front_end/generic_response.rb
|
521
522
|
- lib/brut/front_end/handler.rb
|
522
523
|
- lib/brut/front_end/handlers/csp_reporting_handler.rb
|
523
524
|
- lib/brut/front_end/handlers/instrumentation_handler.rb
|
@@ -610,7 +611,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
610
611
|
- !ruby/object:Gem::Version
|
611
612
|
version: '0'
|
612
613
|
requirements: []
|
613
|
-
rubygems_version: 3.6.
|
614
|
+
rubygems_version: 3.6.7
|
614
615
|
specification_version: 4
|
615
616
|
summary: NOT YET RELEASED - Web Framework Built around Ruby, Web Standards, Simplicity,
|
616
617
|
and Object-Orientation
|