ur 0.2.2 → 0.2.4

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: a39ab1a17905dc8a0fb40eb22896580951abec8cfe78a11c4a1fd558ca6c6917
4
- data.tar.gz: 5915b4da516b30c6ee291eb7f5a5bb5a8f974d30da327d5660a9b1a0549068a8
3
+ metadata.gz: b856342339ad2804ef44731304ee8ecc7801bf090ce019d00751bb8b491df4ff
4
+ data.tar.gz: 75095d90b5e6e4ebff5020fff905a2b52348be06aa2495b8dfe79c730f6e8cc0
5
5
  SHA512:
6
- metadata.gz: e59ca34e85e21e8c659a10e57cffad39d3fa718389bed6ccb6e4327cb33b237569517bb8d5c2eb93272a0c20634966697823a7142f1d861ba58c933dad5342c6
7
- data.tar.gz: 3ab8ad92c6e70fc3dd87928a200a500e8bd5d27440fd9c2b3e35d46d3778aed80122cefda50875cb0bb6f84dcba75fbc24bdc194d88d4f345439b97f98f7b9b6
6
+ metadata.gz: 5934007c613d667498a52cc36238b9d7ff378381945a4d1fceaeb87f4be73cf93af4336701a4a076aea8c1e47de377ada03071a6e0cb52ebf30764bcfd1d1dd5
7
+ data.tar.gz: b6a86b4deac6c7d452aaa46bd828d4695ef954bf085a94d0d86bcbf290e4dcc9759a31eb7b726471f09c8999981a3e455349e07be062411762e3899de6c344a2
data/CHANGELOG.md CHANGED
@@ -1,7 +1,14 @@
1
+ # v0.2.4
2
+
3
+ - JSI = v0.8.0
4
+
5
+ # v0.2.3
6
+
7
+ - JSI v0.7.0
8
+
1
9
  # v0.2.2
2
10
 
3
11
  - Ur::Weblink
4
- - JSI v0.7.0
5
12
  - Ruby 3
6
13
 
7
14
  # v0.2.1
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ur' unless Object.const_defined?(:Ur)
4
+ require 'strscan'
4
5
 
5
6
  module Ur
6
7
  # Ur::ContentType represents a Content-Type header field.
data/lib/ur/version.rb CHANGED
@@ -1 +1 @@
1
- UR_VERSION = "0.2.2".freeze
1
+ UR_VERSION = "0.2.4".freeze
data/lib/ur/weblink.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'ur' unless Object.const_defined?(:Ur)
4
+ require 'strscan'
4
5
 
5
6
  module Ur
6
7
  # a RFC5988 Web Link
@@ -19,6 +20,14 @@ module Ur
19
20
  class NoContextError < Error
20
21
  end
21
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
+
22
31
  # parses an array of Web Links from the value an HTTP Link header, as described in
23
32
  # https://tools.ietf.org/html/rfc5988#section-5
24
33
  #
@@ -28,11 +37,6 @@ module Ur
28
37
 
29
38
  return links unless link_value
30
39
 
31
- attr_char = /[a-zA-Z0-9!#\$&+\-.^_`|~]/ # defined in https://tools.ietf.org/html/rfc5987#section-3.2.1
32
- ptoken = %r([a-zA-Z0-9!#\$%&'()*+\-./:<=>?@\[\]^_`{|}~])
33
- quoted_string = /"([^"]*)"/
34
-
35
- require 'strscan'
36
40
  ss = StringScanner.new(link_value)
37
41
  parse_fail = proc do
38
42
  raise ParseError, "Unable to parse link value: #{link_value} " +
@@ -44,9 +48,7 @@ module Ur
44
48
  ss.scan(/\s*<([^>]+)>/) || parse_fail.call
45
49
  target_uri = ss[1]
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*/)
51
+ while ss.scan(ATTRIBUTE_PAIR)
50
52
  attributes[ss[1]] = ss[2] || ss[3]
51
53
  end
52
54
  links << new(target_uri, attributes, context_uri)
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
 
data/ur.gemspec CHANGED
@@ -1,6 +1,4 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "ur/version"
1
+ require_relative "lib/ur/version"
4
2
 
5
3
  Gem::Specification.new do |spec|
6
4
  spec.name = "ur"
@@ -25,6 +23,6 @@ Gem::Specification.new do |spec|
25
23
 
26
24
  spec.require_paths = ["lib"]
27
25
 
28
- spec.add_dependency "jsi", "~> 0.6"
26
+ spec.add_dependency "jsi", "= 0.8.0"
29
27
  spec.add_dependency "addressable", "~> 2.0"
30
28
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-10 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
19
+ version: 0.8.0
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.6'
26
+ version: 0.8.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: addressable
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  requirements: []
88
- rubygems_version: 3.1.6
88
+ rubygems_version: 3.4.10
89
89
  signing_key:
90
90
  specification_version: 4
91
91
  summary: 'ur: unified request representation'