ur 0.2.3 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 834735162f5c696d940e546b1908bca87a2b0c8e93d3f20247b1468404071b56
4
- data.tar.gz: 6083f1cfaf96c4857c43e580398c512e00589f8e0ef9b799f365d2719d8c1848
3
+ metadata.gz: 8a9b51f120da021be44f14991d4dc1d726fb58b5b70a4bd595ad29ca8af12fff
4
+ data.tar.gz: 373234337bf222a869de55a7bf5bd9ccda0ccf54b469e109832f6962856937ea
5
5
  SHA512:
6
- metadata.gz: 39f8e38f80a35a4d019bed707745d7835fcdc92e8e162dd90a492ce46c711016cb73789ff57d384ac763f8514a5f5749ccc4f1db75a9d4cad4e96a7512ce8be4
7
- data.tar.gz: 4c92cbd6cf2dcb597bd6a265cd7c5a892af3ea504a220e82a7cbcc5e06ef421703ead862e0ba5b6ab88b7633050fe93966befc78c50a76c4f5e23155d65c8a7c
6
+ metadata.gz: 916a05043d591e85b189b364550eca8944302a88b35402d8f46b1a588489cd756039e3dc226c2f3940aa77116d6f3669481f74c9bf620c11766a3dbc09f4ca7e
7
+ data.tar.gz: a6e10766c94d53c3c8a2f87e7d2b911f808cb1ee32a04732e8058c98822a8674b5e1bcd7471f83102a642bc3d5a5767f4e4263b68fe0257d10d7fd04b32bb009
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # v0.2.5
2
+
3
+ - Request and Response #links
4
+ - JSI ~> v0.8.1
5
+
6
+ # v0.2.4
7
+
8
+ - JSI = v0.8.0
9
+
1
10
  # v0.2.3
2
11
 
3
12
  - JSI v0.7.0
@@ -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.3".freeze
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
- # get the attributes: semicolon, some attr_chars, an optional asterisk, equals, and a quoted
48
- # string or series of unquoted ptokens
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 = to_addressable_uri(target_uri)
64
+ @target_uri = JSI::Util.uri(target_uri)
63
65
  @attributes = attributes
64
- @context_uri = to_addressable_uri(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
- private
121
+ include(JSI::Util::Private::FingerprintHash::Immutable)
119
122
 
120
- # if uri is nil, returns nil; otherwise, tries to return a Addressable::URI
121
- def to_addressable_uri(uri)
122
- uri.nil? || uri.is_a?(Addressable::URI) ? uri : Addressable::URI.parse(uri)
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, "expected hash for ur instance. got: #{instance.pretty_inspect.chomp}")
36
+ raise(TypeError, "Epected Ur instance content to be a Hash. Got: #{instance.pretty_inspect.chomp}")
37
37
  end
38
38
 
39
- JSI::SchemaSet[schema, *schemas].new_jsi(instance, **options).tap do |ur|
40
- ur.request = {} if ur.request.nil?
41
- ur.response = {} if ur.response.nil?
42
- ur.metadata = {} if ur.metadata.nil?
43
- end
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"].rewind
80
- ur.request.body = env["rack.input"].read
81
- env["rack.input"].rewind
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 [logger] a tagged logger
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
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "jsi", "~> 0.7"
26
+ spec.add_dependency "jsi", "~> 0.8.1"
27
27
  spec.add_dependency "addressable", "~> 2.0"
28
28
  end
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.3
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: 2023-07-29 00:00:00.000000000 Z
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: '0.7'
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: '0.7'
26
+ version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement