ur 0.2.3 → 0.2.5
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/CHANGELOG.md +9 -0
- data/lib/ur/request_and_response.rb +8 -0
- data/lib/ur/version.rb +1 -1
- data/lib/ur/weblink.rb +25 -17
- data/lib/ur.rb +13 -11
- data/ur.gemspec +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: 8a9b51f120da021be44f14991d4dc1d726fb58b5b70a4bd595ad29ca8af12fff
|
4
|
+
data.tar.gz: 373234337bf222a869de55a7bf5bd9ccda0ccf54b469e109832f6962856937ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 916a05043d591e85b189b364550eca8944302a88b35402d8f46b1a588489cd756039e3dc226c2f3940aa77116d6f3669481f74c9bf620c11766a3dbc09f4ca7e
|
7
|
+
data.tar.gz: a6e10766c94d53c3c8a2f87e7d2b911f808cb1ee32a04732e8058c98822a8674b5e1bcd7471f83102a642bc3d5a5767f4e4263b68fe0257d10d7fd04b32bb009
|
data/CHANGELOG.md
CHANGED
@@ -41,6 +41,14 @@ module Ur
|
|
41
41
|
content_type ? content_type.media_type : nil
|
42
42
|
end
|
43
43
|
|
44
|
+
# @return [Enumerable<Weblink>]
|
45
|
+
def links
|
46
|
+
headers.each do |k, v|
|
47
|
+
return(Weblink.parse_link_value(v, ur.request.uri)) if k =~ /\Alink\z/i
|
48
|
+
end
|
49
|
+
[].freeze
|
50
|
+
end
|
51
|
+
|
44
52
|
# is our content type JSON?
|
45
53
|
# @return [Boolean]
|
46
54
|
def json?
|
data/lib/ur/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
UR_VERSION = "0.2.
|
1
|
+
UR_VERSION = "0.2.5".freeze
|
data/lib/ur/weblink.rb
CHANGED
@@ -20,6 +20,14 @@ module Ur
|
|
20
20
|
class NoContextError < Error
|
21
21
|
end
|
22
22
|
|
23
|
+
ATTR_CHAR = /[a-zA-Z0-9!#\$&+\-.^_`|~]/.freeze # defined in https://tools.ietf.org/html/rfc5987#section-3.2.1
|
24
|
+
PTOKEN = %r([a-zA-Z0-9!#\$%&'()*+\-./:<=>?@\[\]^_`{|}~]).freeze
|
25
|
+
QUOTED_STRING = /"([^"]*)"/.freeze
|
26
|
+
|
27
|
+
# attributes: semicolon, some attr_chars, an optional asterisk, equals, and a quoted
|
28
|
+
# string or series of unquoted ptokens
|
29
|
+
ATTRIBUTE_PAIR = /\s*;\s*(#{ATTR_CHAR.source}+\*?)\s*=\s*(?:#{QUOTED_STRING.source}|(#{PTOKEN.source}+))\s*/.freeze
|
30
|
+
|
23
31
|
# parses an array of Web Links from the value an HTTP Link header, as described in
|
24
32
|
# https://tools.ietf.org/html/rfc5988#section-5
|
25
33
|
#
|
@@ -29,10 +37,6 @@ module Ur
|
|
29
37
|
|
30
38
|
return links unless link_value
|
31
39
|
|
32
|
-
attr_char = /[a-zA-Z0-9!#\$&+\-.^_`|~]/ # defined in https://tools.ietf.org/html/rfc5987#section-3.2.1
|
33
|
-
ptoken = %r([a-zA-Z0-9!#\$%&'()*+\-./:<=>?@\[\]^_`{|}~])
|
34
|
-
quoted_string = /"([^"]*)"/
|
35
|
-
|
36
40
|
ss = StringScanner.new(link_value)
|
37
41
|
parse_fail = proc do
|
38
42
|
raise ParseError, "Unable to parse link value: #{link_value} " +
|
@@ -42,26 +46,25 @@ module Ur
|
|
42
46
|
while !ss.eos?
|
43
47
|
# get the target_uri, within some angle brackets
|
44
48
|
ss.scan(/\s*<([^>]+)>/) || parse_fail.call
|
45
|
-
target_uri = ss[1]
|
49
|
+
target_uri = JSI::Util.uri(ss[1].freeze)
|
46
50
|
attributes = {}
|
47
|
-
|
48
|
-
|
49
|
-
while ss.scan(/\s*;\s*(#{attr_char.source}+\*?)\s*=\s*(?:#{quoted_string.source}|(#{ptoken.source}+))\s*/)
|
50
|
-
attributes[ss[1]] = ss[2] || ss[3]
|
51
|
+
while ss.scan(ATTRIBUTE_PAIR)
|
52
|
+
attributes[ss[1].freeze] = (ss[2] || ss[3]).freeze
|
51
53
|
end
|
52
|
-
links << new(target_uri, attributes, context_uri)
|
54
|
+
links << new(target_uri, attributes.freeze, context_uri)
|
53
55
|
unless ss.eos?
|
54
56
|
# either the string ends or has a comma followed by another link
|
55
57
|
ss.scan(/\s*,\s*/) || parse_fail.call
|
56
58
|
end
|
57
59
|
end
|
58
|
-
links
|
60
|
+
links.freeze
|
59
61
|
end
|
60
62
|
|
61
63
|
def initialize(target_uri, attributes, context_uri=nil)
|
62
|
-
@target_uri =
|
64
|
+
@target_uri = JSI::Util.uri(target_uri)
|
63
65
|
@attributes = attributes
|
64
|
-
@context_uri =
|
66
|
+
@context_uri = JSI::Util.uri(context_uri)
|
67
|
+
freeze
|
65
68
|
end
|
66
69
|
|
67
70
|
# the context uri of the link, as an Addressable URI. this URI must be absolute, and the target_uri
|
@@ -115,11 +118,16 @@ module Ur
|
|
115
118
|
"<#{target_uri}>" + attributes.map { |k,v| %Q(; #{k}="#{v}") }.join('')
|
116
119
|
end
|
117
120
|
|
118
|
-
|
121
|
+
include(JSI::Util::Private::FingerprintHash::Immutable)
|
119
122
|
|
120
|
-
#
|
121
|
-
def
|
122
|
-
|
123
|
+
# @private
|
124
|
+
def jsi_fingerprint
|
125
|
+
{
|
126
|
+
class: Weblink,
|
127
|
+
target_uri: @target_uri,
|
128
|
+
attributes: @attributes,
|
129
|
+
context_uri: @context_uri,
|
130
|
+
}.freeze
|
123
131
|
end
|
124
132
|
end
|
125
133
|
end
|
data/lib/ur.rb
CHANGED
@@ -31,16 +31,16 @@ module Ur
|
|
31
31
|
autoload :ContentType, 'ur/content_type'
|
32
32
|
|
33
33
|
class << self
|
34
|
-
def new(instance = {}, schemas: Set[], **options)
|
34
|
+
def new(instance = {}, schemas: Set[], mutable: true, **options)
|
35
35
|
unless instance.respond_to?(:to_hash)
|
36
|
-
raise(TypeError, "
|
36
|
+
raise(TypeError, "Epected Ur instance content to be a Hash. Got: #{instance.pretty_inspect.chomp}")
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
instance = instance.merge({'request' => {}}) if !instance['request']
|
40
|
+
instance = instance.merge({'response' => {}}) if !instance['response']
|
41
|
+
instance = instance.merge({'metadata' => {}}) if !instance['metadata']
|
42
|
+
|
43
|
+
JSI::SchemaSet[schema, *schemas].new_jsi(instance, mutable: mutable, **options)
|
44
44
|
end
|
45
45
|
|
46
46
|
def from_rack_request(request_env, **options)
|
@@ -76,9 +76,11 @@ module Ur
|
|
76
76
|
end
|
77
77
|
end.compact.inject({}, &:update)
|
78
78
|
|
79
|
-
env["rack.input"]
|
80
|
-
|
81
|
-
|
79
|
+
if env["rack.input"]
|
80
|
+
env["rack.input"].rewind
|
81
|
+
ur.request.body = env["rack.input"].read
|
82
|
+
env["rack.input"].rewind
|
83
|
+
end
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
@@ -94,7 +96,7 @@ module Ur
|
|
94
96
|
|
95
97
|
# Ur#logger_tags applies tags from a tagged logger to this ur's metadata.
|
96
98
|
# note: ur does not log anything and this logger is not stored.
|
97
|
-
# @param
|
99
|
+
# @param logger a tagged logger
|
98
100
|
# @return [void]
|
99
101
|
def logger_tags(logger)
|
100
102
|
if logger && logger.formatter.respond_to?(:current_tags)
|
data/ur.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jsi
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.8.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.8.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: addressable
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|