Skip to content

Commit 9c9e551

Browse files
committed
Finish 2.2.10
2 parents 5484aad + 76ea1fb commit 9c9e551

6 files changed

Lines changed: 54 additions & 24 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.9
1+
2.2.10

lib/rdf.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,19 @@ def self.Node(*args, &block)
9393
#
9494
# @param (see RDF::URI#initialize)
9595
# @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)
9898
end
9999

100100
##
101101
# Alias for `RDF::Literal.new`.
102102
#
103103
# @param (see RDF::Literal#initialize)
104104
# @return [RDF::Literal]
105-
def self.Literal(*args, &block)
106-
case literal = args.first
105+
def self.Literal(literal, *args, &block)
106+
case literal
107107
when RDF::Literal then literal
108-
else Literal.new(*args, &block)
108+
else Literal.new(literal, *args, &block)
109109
end
110110
end
111111

@@ -220,12 +220,14 @@ def self.respond_to?(method, include_all = false)
220220
super || RDF::RDFV.respond_to?(method, include_all)
221221
end
222222

223+
RDF_N_REGEXP = %r{_\d+}.freeze
224+
223225
##
224226
# Delegate other methods to RDF::RDFV
225227
def self.method_missing(property, *args, &block)
226228
if args.empty?
227229
# 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)
229231
else
230232
super
231233
end

lib/rdf/model/uri.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class URI
8181
IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze
8282

8383
# Split an IRI into it's component parts
84-
IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/
84+
IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/.freeze
8585

8686
# Remove dot expressions regular expressions
8787
RDS_2A = /^\.?\.\/(.*)$/.freeze
@@ -141,10 +141,9 @@ def self.cache
141141
#
142142
# @param (see #initialize)
143143
# @return [RDF::URI] an immutable, frozen URI object
144-
def self.intern(*args)
145-
str = args.first
144+
def self.intern(str, *args)
146145
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
148147
end
149148

150149
##
@@ -224,6 +223,7 @@ def self.normalize_path(path)
224223
# @param [Boolean] validate (false)
225224
# @param [Boolean] canonicalize (false)
226225
def initialize(*args, validate: false, canonicalize: false, **options)
226+
@value = @object = @hash = nil
227227
uri = args.first
228228
if uri
229229
@value = uri.to_s
@@ -344,7 +344,7 @@ def length
344344
# @return [Boolean] `true` or `false`
345345
# @since 0.3.9
346346
def valid?
347-
to_s.match(RDF::URI::IRI) || false
347+
RDF::URI::IRI.match(to_s) || false
348348
end
349349

350350
##
@@ -796,7 +796,8 @@ def inspect
796796
# lexical representation of URI, either absolute or relative
797797
# @return [String]
798798
def value
799-
@value ||= [
799+
return @value if @value
800+
@value = [
800801
("#{scheme}:" if absolute?),
801802
("//#{authority}" if authority),
802803
path,
@@ -810,15 +811,15 @@ def value
810811
#
811812
# @return [Integer]
812813
def hash
813-
@hash ||= (value.hash * -1)
814+
@hash || @hash = (value.hash * -1)
814815
end
815816

816817
##
817818
# Returns object representation of this URI, broken into components
818819
#
819820
# @return [Hash{Symbol => String}]
820821
def object
821-
@object ||= parse(@value)
822+
@object || @object = parse(@value)
822823
end
823824
alias_method :to_h, :object
824825

@@ -830,8 +831,8 @@ def object
830831
def parse(value)
831832
value = value.to_s.dup.force_encoding(Encoding::ASCII_8BIT)
832833
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]
835836
userinfo, hostport = authority.to_s.split('@', 2)
836837
hostport, userinfo = userinfo, nil unless hostport
837838
user, password = userinfo.to_s.split(':', 2)
@@ -928,11 +929,13 @@ def normalized_password
928929
::URI.encode(::URI.decode(password), /[^#{IUNRESERVED}|#{SUB_DELIMS}]/) if password
929930
end
930931

932+
HOST_FROM_AUTHORITY_RE = /(?:[^@]+@)?([^:]+)(?::.*)?$/.freeze
933+
931934
##
932935
# @return [String]
933936
def host
934937
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]))
936939
end
937940
end
938941

@@ -954,11 +957,13 @@ def normalized_host
954957
normalize_segment(host, IHOST, true).chomp('.') if host
955958
end
956959

960+
PORT_FROM_AUTHORITY_RE = /:(\d+)$/.freeze
961+
957962
##
958963
# @return [String]
959964
def port
960965
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]))
962967
end
963968
end
964969

lib/rdf/util/logger.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ def log_depth(**options, &block)
192192
end
193193

194194
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+
195200
##
196201
# Common method for logging messages
197202
#
@@ -212,8 +217,8 @@ def logger_common(*args, level:, **options)
212217
logger = self.logger(options)
213218
logger.log_statistics[level] = logger.log_statistics[level].to_i + 1
214219
# 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)
217222

218223
depth = options.fetch(:depth, logger.log_depth)
219224
args << yield if block_given?

lib/rdf/vocabulary.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def imported_from
273273
#
274274
# @return [RDF::URI]
275275
def to_uri
276-
RDF::URI.intern(to_s)
276+
RDF::URI.intern(@@uris[self].to_s)
277277
end
278278

279279
# For IRI compatibility
@@ -448,7 +448,7 @@ def props; @properties ||= {}; end
448448
undef_method(*instance_methods.
449449
map(&:to_s).
450450
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] == '__'}.
452452
map(&:to_sym))
453453

454454
##
@@ -623,7 +623,7 @@ def dup
623623
# @since 0.3.9
624624
def valid?
625625
# Validate relative to RFC3987
626-
to_s.match(RDF::URI::IRI) || false
626+
RDF::URI::IRI.match(to_s) || false
627627
end
628628

629629
##

spec/vocabulary_spec.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@
2727
expect(subject["foo"]).to be_a(RDF::Vocabulary::Term)
2828
end
2929

30+
it "allows #send" do
31+
expect {subject.send(:foo)}.not_to raise_error
32+
expect(subject.send(:foo)).to be_a(RDF::Vocabulary::Term)
33+
end
34+
35+
it "allows #public_send" do
36+
expect {subject.public_send(:foo)}.not_to raise_error
37+
expect(subject.public_send(:foo)).to be_a(RDF::Vocabulary::Term)
38+
end
39+
3040
it "does not add to @@uris" do
3141
RDF::Vocabulary.new("http://example/")
3242
expect(RDF::Vocabulary.class_variable_get(:"@@uris")).to be_a(Hash)
@@ -347,6 +357,14 @@
347357
end
348358
end
349359

360+
context 'without a uri' do
361+
let!(:vocab) { @vocab ||= RDF::Vocabulary.from_graph(graph) }
362+
363+
it "gives a null relative uri" do
364+
expect(vocab.to_uri).to eq RDF::URI.new(nil)
365+
end
366+
end
367+
350368
context "with existing Vocabulary" do
351369
let!(:nt) {%{
352370
<http://example/Klass> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .

0 commit comments

Comments
 (0)