rdf 2.2.9 → 2.2.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c1a5dbdabcabf42a336dcd47777e3bca134a2fa
4
- data.tar.gz: 0dd66ec264c9dd2b475a12d615fe88bb6ef73a91
3
+ metadata.gz: d84b3c8827d268301a7b6b9e0c96b80da7f68e20
4
+ data.tar.gz: 4f1b1330f1c11280fcdbaff3ab68c32d42ac7554
5
5
  SHA512:
6
- metadata.gz: 56a8bcbe0ce7eb75dfb7854efe9dfabdb17ad2f05895ac0c3f5d6084a004a97fd51b1b5a58084823e18f844f41676cdafe9be8e3fd0ebf808b0c0572e44cc9fc
7
- data.tar.gz: c069aa63600fb1d0b50179c1aa0f2314bed3463eb087c7589661cc5b804dafab1155ae181cc867d85917c18b8e51576294b25e66830bd9ed55a4850a16128c96
6
+ metadata.gz: 851e0ce7185a984c98fd3c6c9eea428602b782ceac932419b61c120178903eca03c6cdbfd97b89c2add9cbacbb8d1ca83950f7309b7749500f72263bbad52016
7
+ data.tar.gz: 7da0bbaff16670a2981049a4b0ef90ea6759d642ef73c4b8393d6afbad0ff280406f715b7bb5d20e8473f8ad9952d2e46cf3b3d5813ea1d13694bd63c82f07f5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.9
1
+ 2.2.10
data/lib/rdf.rb CHANGED
@@ -93,8 +93,8 @@ module RDF
93
93
  #
94
94
  # @param (see RDF::URI#initialize)
95
95
  # @return [RDF::URI]
96
- def self.URI(*args, &block)
97
- (uri = args.first).respond_to?(:to_uri) ? uri.to_uri : URI.new(*args, &block)
96
+ def self.URI(uri, *args, &block)
97
+ uri.respond_to?(:to_uri) ? uri.to_uri : URI.new(uri, *args, &block)
98
98
  end
99
99
 
100
100
  ##
@@ -102,10 +102,10 @@ module RDF
102
102
  #
103
103
  # @param (see RDF::Literal#initialize)
104
104
  # @return [RDF::Literal]
105
- def self.Literal(*args, &block)
106
- case literal = args.first
105
+ def self.Literal(literal, *args, &block)
106
+ case literal
107
107
  when RDF::Literal then literal
108
- else Literal.new(*args, &block)
108
+ else Literal.new(literal, *args, &block)
109
109
  end
110
110
  end
111
111
 
@@ -220,12 +220,14 @@ module RDF
220
220
  super || RDF::RDFV.respond_to?(method, include_all)
221
221
  end
222
222
 
223
+ RDF_N_REGEXP = %r{_\d+}.freeze
224
+
223
225
  ##
224
226
  # Delegate other methods to RDF::RDFV
225
227
  def self.method_missing(property, *args, &block)
226
228
  if args.empty?
227
229
  # Special-case rdf:_n for all integers
228
- property.to_s =~ %r{_\d+} ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV.send(property)
230
+ RDF_N_REGEXP.match(property) ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV.send(property)
229
231
  else
230
232
  super
231
233
  end
@@ -81,7 +81,7 @@ module RDF
81
81
  IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
82
82
 
83
83
  # Split an IRI into it's component parts
84
- IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/
84
+ IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/.freeze
85
85
 
86
86
  # Remove dot expressions regular expressions
87
87
  RDS_2A = /^\.?\.\/(.*)$/.freeze
@@ -141,10 +141,9 @@ module RDF
141
141
  #
142
142
  # @param (see #initialize)
143
143
  # @return [RDF::URI] an immutable, frozen URI object
144
- def self.intern(*args)
145
- str = args.first
144
+ def self.intern(str, *args)
146
145
  args << {} unless args.last.is_a?(Hash) # FIXME: needed until #to_hash is removed to avoid DEPRECATION warning.
147
- (cache[(str = str.to_s).to_sym] ||= self.new(*args)).freeze
146
+ (cache[(str = str.to_s).to_sym] ||= self.new(str, *args)).freeze
148
147
  end
149
148
 
150
149
  ##
@@ -224,6 +223,7 @@ module RDF
224
223
  # @param [Boolean] validate (false)
225
224
  # @param [Boolean] canonicalize (false)
226
225
  def initialize(*args, validate: false, canonicalize: false, **options)
226
+ @value = @object = @hash = nil
227
227
  uri = args.first
228
228
  if uri
229
229
  @value = uri.to_s
@@ -344,7 +344,7 @@ module RDF
344
344
  # @return [Boolean] `true` or `false`
345
345
  # @since 0.3.9
346
346
  def valid?
347
- to_s.match(RDF::URI::IRI) || false
347
+ RDF::URI::IRI.match(to_s) || false
348
348
  end
349
349
 
350
350
  ##
@@ -796,7 +796,8 @@ module RDF
796
796
  # lexical representation of URI, either absolute or relative
797
797
  # @return [String]
798
798
  def value
799
- @value ||= [
799
+ return @value if @value
800
+ @value = [
800
801
  ("#{scheme}:" if absolute?),
801
802
  ("//#{authority}" if authority),
802
803
  path,
@@ -810,7 +811,7 @@ module RDF
810
811
  #
811
812
  # @return [Integer]
812
813
  def hash
813
- @hash ||= (value.hash * -1)
814
+ @hash || @hash = (value.hash * -1)
814
815
  end
815
816
 
816
817
  ##
@@ -818,7 +819,7 @@ module RDF
818
819
  #
819
820
  # @return [Hash{Symbol => String}]
820
821
  def object
821
- @object ||= parse(@value)
822
+ @object || @object = parse(@value)
822
823
  end
823
824
  alias_method :to_h, :object
824
825
 
@@ -830,8 +831,8 @@ module RDF
830
831
  def parse(value)
831
832
  value = value.to_s.dup.force_encoding(Encoding::ASCII_8BIT)
832
833
  parts = {}
833
- if matchdata = value.to_s.match(IRI_PARTS)
834
- scheme, authority, path, query, fragment = matchdata.to_a[1..-1]
834
+ if matchdata = IRI_PARTS.match(value)
835
+ scheme, authority, path, query, fragment = matchdata[1..-1]
835
836
  userinfo, hostport = authority.to_s.split('@', 2)
836
837
  hostport, userinfo = userinfo, nil unless hostport
837
838
  user, password = userinfo.to_s.split(':', 2)
@@ -928,11 +929,13 @@ module RDF
928
929
  ::URI.encode(::URI.decode(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if password
929
930
  end
930
931
 
932
+ HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
933
+
931
934
  ##
932
935
  # @return [String]
933
936
  def host
934
937
  object.fetch(:host) do
935
- @object[:host] = ($1 if @object[:authority].to_s.match(/(?:[^@]+@)?([^:]+)(?::.*)?$/))
938
+ @object[:host] = ($1 if HOST_FROM_AUTHORITY_RE.match(@object[:authority]))
936
939
  end
937
940
  end
938
941
 
@@ -954,11 +957,13 @@ module RDF
954
957
  normalize_segment(host, IHOST, true).chomp('.') if host
955
958
  end
956
959
 
960
+ PORT_FROM_AUTHORITY_RE = /:(\d+)$/.freeze
961
+
957
962
  ##
958
963
  # @return [String]
959
964
  def port
960
965
  object.fetch(:port) do
961
- @object[:port] = ($1 if @object[:authority].to_s.match(/:(\d+)$/))
966
+ @object[:port] = ($1 if PORT_FROM_AUTHORITY_RE.match(@object[:authority]))
962
967
  end
963
968
  end
964
969
 
@@ -192,6 +192,11 @@ module RDF; module Util
192
192
  end
193
193
 
194
194
  private
195
+ LOGGER_COMMON_LEVELS = {
196
+ fatal: 4, error: 3, warn: 2, info: 1, debug: 0
197
+ }.freeze
198
+ LOGGER_COMMON_LEVELS_REVERSE = LOGGER_COMMON_LEVELS.invert.freeze
199
+
195
200
  ##
196
201
  # Common method for logging messages
197
202
  #
@@ -212,8 +217,8 @@ module RDF; module Util
212
217
  logger = self.logger(options)
213
218
  logger.log_statistics[level] = logger.log_statistics[level].to_i + 1
214
219
  # Some older code uses integer level numbers
215
- level = [:debug, :info, :warn, :error, :fatal][level] if level.is_a?(Integer)
216
- return if logger.level > {fatal: 4, error: 3, warn: 2, info: 1, debug: 0}[level]
220
+ level = LOGGER_COMMON_LEVELS_REVERSE.fetch(level) if level.is_a?(Integer)
221
+ return if logger.level > LOGGER_COMMON_LEVELS.fetch(level)
217
222
 
218
223
  depth = options.fetch(:depth, logger.log_depth)
219
224
  args << yield if block_given?
@@ -273,7 +273,7 @@ module RDF
273
273
  #
274
274
  # @return [RDF::URI]
275
275
  def to_uri
276
- RDF::URI.intern(to_s)
276
+ RDF::URI.intern(@@uris[self].to_s)
277
277
  end
278
278
 
279
279
  # For IRI compatibility
@@ -448,7 +448,7 @@ module RDF
448
448
  undef_method(*instance_methods.
449
449
  map(&:to_s).
450
450
  select {|m| m =~ /^\w+$/}.
451
- reject {|m| %w(object_id dup instance_eval inspect to_s class).include?(m) || m[0,2] == '__'}.
451
+ reject {|m| %w(object_id dup instance_eval inspect to_s class send public_send).include?(m) || m[0,2] == '__'}.
452
452
  map(&:to_sym))
453
453
 
454
454
  ##
@@ -623,7 +623,7 @@ module RDF
623
623
  # @since 0.3.9
624
624
  def valid?
625
625
  # Validate relative to RFC3987
626
- to_s.match(RDF::URI::IRI) || false
626
+ RDF::URI::IRI.match(to_s) || false
627
627
  end
628
628
 
629
629
  ##
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.9
4
+ version: 2.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-08-27 00:00:00.000000000 Z
13
+ date: 2017-09-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header