Skip to content

Commit 7c7ad14

Browse files
committed
Finish 3.0.1
2 parents 5b1ad24 + cea7191 commit 7c7ad14

File tree

5 files changed

+23
-4
lines changed

5 files changed

+23
-4
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.0
1+
3.0.1

lib/rdf/format.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class Format
6565
# Only return a format having a writer.
6666
# @param [String, Proc] sample (nil)
6767
# A sample of input used for performing format detection. If we find no formats, or we find more than one, and we have a sample, we can perform format detection to find a specific format to use, in which case we pick the last one we find
68+
# @param [Boolean] all_if_none (true)
69+
# Returns all formats if none match, otherwise no format. Note that having a `sample` overrides this, and will search through all formats, or all those filtered to find a sample that matches
6870
# @yield [klass]
6971
# @yieldparam [Class]
7072
# @return [Enumerator]
@@ -74,6 +76,7 @@ def self.each(file_name: nil,
7476
has_reader: false,
7577
has_writer: false,
7678
sample: nil,
79+
all_if_none: true,
7780
**options,
7881
&block)
7982
formats = case
@@ -106,7 +109,7 @@ def self.each(file_name: nil,
106109
when file_extension
107110
file_extensions[file_extension.to_sym]
108111
else
109-
@@subclasses
112+
all_if_none ? @@subclasses : nil
110113
end || (sample ? @@subclasses : []) # If we can sample, check all classes
111114

112115
# Subset by available reader or writer
@@ -181,7 +184,7 @@ def self.for(*args, **options, &block)
181184
end
182185
classes
183186
else
184-
self.each(options).to_a
187+
self.each(options.merge(all_if_none: false)).to_a
185188
end
186189

187190
# Return the last detected format

lib/rdf/vocabulary.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ def expand_pname(pname)
304304
# @param [RDF::URI] uri
305305
# @return [Vocabulary]
306306
def find(uri)
307+
uri = RDF::URI(uri) if uri.is_a?(String)
308+
return nil unless uri.uri? && uri.valid?
307309
RDF::Vocabulary.detect do |v|
308310
if uri.length >= v.to_uri.length
309-
RDF::URI(uri).start_with?(v.to_uri)
311+
uri.start_with?(v.to_uri)
310312
else
311313
v.to_uri.to_s.sub(%r([/#]$), '') == uri.to_s
312314
end

spec/format_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def self.to_sym; :foo_bar; end
6161
end
6262
end
6363

64+
it "returns no formats if none match" do
65+
expect(RDF::Format.for).to be_nil
66+
end
67+
6468
it "returns any format for content_type: */*" do
6569
expect(RDF::Format.for(content_type: '*/*')).to be_a(Class)
6670
end

spec/vocabulary_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@
324324
expect(RDF::Vocabulary.find(term.to_s)).to equal vocab
325325
end
326326
end
327+
it "returns nil if argument is a BNode" do
328+
terms.each do |term, vocab|
329+
expect(RDF::Vocabulary.find(RDF::Node.new("a"))).to be_nil
330+
end
331+
end
332+
it "returns nil if argument an invalid URI" do
333+
terms.each do |term, vocab|
334+
expect(RDF::Vocabulary.find("a b c")).to be_nil
335+
end
336+
end
327337
end
328338

329339
describe ".find_term" do

0 commit comments

Comments
 (0)