primate-run 0.5.0 → 0.6.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/lib/primate/request.rb +0 -2
- data/lib/primate/request_body.rb +20 -25
- data/lib/primate/response.rb +4 -2
- data/lib/primate/route.rb +6 -9
- data/lib/primate/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0f83843c5b0fa350eec8aa6c38b3d2bd3277707d8c8dbeff6c4d1f1a655ae31c
|
|
4
|
+
data.tar.gz: 25bb52f15b1d6bb0afa45098d230c132a5c61a7da54b717d88bf7771ed8694b0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 94a76367d2d7d059a4e1bd7403228d339900bb663843b94746549b66fe7ce46bc5671926da67348e6fa1ca407aecc231be9da15a1681d76ea072e6c3fb4a3825
|
|
7
|
+
data.tar.gz: e6dbcc74893720e392afd29f82b50ed8790e00b96e81de31862c54a70404f99e5830e0cde2e0501a5d80c8709c864b6080b1dfa63633fc28895395f396556275
|
data/lib/primate/request.rb
CHANGED
|
@@ -7,8 +7,6 @@ require_relative 'request_body'
|
|
|
7
7
|
class Request
|
|
8
8
|
attr_reader :url, :body, :path, :query, :headers, :cookies
|
|
9
9
|
|
|
10
|
-
# @param request [Object] JavaScript request object from the runtime
|
|
11
|
-
# @param helpers [Object] Helper functions from JavaScript runtime
|
|
12
10
|
def initialize(request, helpers)
|
|
13
11
|
@url = Primate::URL.new(request['url'])
|
|
14
12
|
@body = RequestBody.new(request['body'], helpers)
|
data/lib/primate/request_body.rb
CHANGED
|
@@ -4,43 +4,38 @@ require 'json'
|
|
|
4
4
|
require_relative 'readable'
|
|
5
5
|
require_relative 'uploaded_file'
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
class Multipart
|
|
8
|
+
attr_reader :form, :files
|
|
9
|
+
|
|
10
|
+
def initialize(form, files)
|
|
11
|
+
@form = form
|
|
12
|
+
@files = files
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
8
16
|
class RequestBody
|
|
9
|
-
# Initialize with JavaScript body object
|
|
10
|
-
#
|
|
11
|
-
# @param body [Object] JavaScript body object from runtime
|
|
12
|
-
# @param helpers [Object] Helper functions from JavaScript runtime
|
|
13
17
|
def initialize(body, helpers)
|
|
14
18
|
@body = body
|
|
15
19
|
@helpers = helpers
|
|
16
20
|
end
|
|
17
21
|
|
|
18
|
-
# Get body as JSON (parsed hash)
|
|
19
|
-
#
|
|
20
|
-
# @return [Hash] Parsed JSON data
|
|
21
22
|
def json
|
|
22
|
-
JSON.parse(@body.
|
|
23
|
+
JSON.parse(@body.jsonSync.to_s)
|
|
23
24
|
end
|
|
24
25
|
|
|
25
|
-
# Get body as plain text
|
|
26
|
-
#
|
|
27
|
-
# @return [String] Body as string
|
|
28
26
|
def text
|
|
29
|
-
@body.
|
|
27
|
+
@body.textSync.to_s
|
|
30
28
|
end
|
|
31
29
|
|
|
32
|
-
# Get form as hash
|
|
33
|
-
#
|
|
34
|
-
# @return [Hash] Form data
|
|
35
30
|
def form
|
|
36
|
-
JSON.parse(@body.
|
|
31
|
+
JSON.parse(@body.formSync.to_s)
|
|
37
32
|
end
|
|
38
33
|
|
|
39
|
-
def
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Array.new(
|
|
43
|
-
f =
|
|
34
|
+
def multipart
|
|
35
|
+
form = JSON.parse(@body.formSync.to_s)
|
|
36
|
+
files_js = @body.filesSync
|
|
37
|
+
files = Array.new(files_js[:length].to_i) do |i|
|
|
38
|
+
f = files_js[i]
|
|
44
39
|
Primate::UploadedFile.new(
|
|
45
40
|
field: f['field'].to_s,
|
|
46
41
|
name: f['name'].to_s,
|
|
@@ -49,10 +44,10 @@ class RequestBody
|
|
|
49
44
|
bytes: f['bytes']
|
|
50
45
|
)
|
|
51
46
|
end
|
|
47
|
+
Multipart.new(form, files)
|
|
52
48
|
end
|
|
53
49
|
|
|
54
|
-
def
|
|
55
|
-
|
|
56
|
-
Primate::Readable.new(binary['buffer'], binary['mime'].to_s)
|
|
50
|
+
def blob
|
|
51
|
+
Primate::Readable.new(@body.blobSync, @body.blobTypeSync.to_s)
|
|
57
52
|
end
|
|
58
53
|
end
|
data/lib/primate/response.rb
CHANGED
|
@@ -16,8 +16,10 @@ module Response
|
|
|
16
16
|
# @param location [String] URL to redirect to
|
|
17
17
|
# @param options [Hash] Redirect options (status code, etc.)
|
|
18
18
|
# @return [Hash] Response object for the Primate framework
|
|
19
|
-
def self.redirect(location,
|
|
20
|
-
{ __PRMT__: 'redirect', location: location
|
|
19
|
+
def self.redirect(location, status = nil)
|
|
20
|
+
result = { __PRMT__: 'redirect', location: location }
|
|
21
|
+
result[:status] = status if status
|
|
22
|
+
result
|
|
21
23
|
end
|
|
22
24
|
|
|
23
25
|
# Create an error response
|
data/lib/primate/route.rb
CHANGED
|
@@ -10,28 +10,25 @@ module Route
|
|
|
10
10
|
@current_scope = "__global__"
|
|
11
11
|
|
|
12
12
|
class << self
|
|
13
|
-
# set the active scope for subsequent handler registrations
|
|
14
13
|
def scope(id)
|
|
15
14
|
@current_scope = id.to_s
|
|
16
15
|
@registry[@current_scope]
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
# clear routes for a specific scope (or the current scope if none given)
|
|
20
18
|
def clear(id = nil)
|
|
21
19
|
target = (id || @current_scope).to_s
|
|
22
20
|
@registry.delete(target)
|
|
23
21
|
@registry[target] = {}
|
|
24
22
|
end
|
|
25
23
|
|
|
26
|
-
# return the verb->handler map for a scope (read-only use)
|
|
27
24
|
def registry(id = nil)
|
|
28
25
|
@registry[(id || @current_scope).to_s]
|
|
29
26
|
end
|
|
30
27
|
|
|
31
28
|
%w[GET POST PUT PATCH DELETE HEAD OPTIONS CONNECT TRACE].each do |verb|
|
|
32
|
-
define_method(verb.downcase) do
|
|
29
|
+
define_method(verb.downcase) do |content_type: nil, &block|
|
|
33
30
|
raise ArgumentError, "block required" unless block
|
|
34
|
-
registry[verb] = block
|
|
31
|
+
registry[verb] = { handler: block, content_type: content_type }
|
|
35
32
|
end
|
|
36
33
|
end
|
|
37
34
|
|
|
@@ -47,12 +44,12 @@ module Route
|
|
|
47
44
|
set_session(session, helpers)
|
|
48
45
|
set_i18n(i18n)
|
|
49
46
|
|
|
50
|
-
request = Request.new(js_req, helpers)
|
|
51
47
|
verb_up = verb.to_s.upcase
|
|
52
|
-
|
|
53
|
-
return Response.error(status: 404) unless
|
|
48
|
+
entry = @registry.dig(scope_id.to_s, verb_up)
|
|
49
|
+
return Response.error(status: 404) unless entry
|
|
54
50
|
|
|
55
|
-
|
|
51
|
+
request = Request.new(js_req, helpers)
|
|
52
|
+
entry[:handler].call(request)
|
|
56
53
|
end
|
|
57
54
|
end
|
|
58
55
|
end
|
data/lib/primate/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: primate-run
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Primate Team
|
|
@@ -15,14 +15,14 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - "~>"
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '4.0'
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - "~>"
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '4.0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rake
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -88,7 +88,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
88
88
|
requirements:
|
|
89
89
|
- - ">="
|
|
90
90
|
- !ruby/object:Gem::Version
|
|
91
|
-
version: 3.
|
|
91
|
+
version: 3.4.0
|
|
92
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
94
|
- - ">="
|