Skip to content

Commit

Permalink
Finish 3.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Apr 22, 2022
2 parents 84063a9 + 8573895 commit 2b73d12
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 11 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,31 @@ jobs:
if: "matrix.ruby == '3.0'"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
wintests:
name: Win64 Ruby ${{ matrix.ruby }}
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
runs-on: windows-latest
env:
CI: true
ALLOW_FAILURES: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'jruby' }}
strategy:
fail-fast: false
matrix:
ruby:
- 3.1
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
- name: Install dependencies
run: bundle install --jobs 4 --retry 3
- name: Run tests
run: ruby --version; bundle exec rspec spec || $ALLOW_FAILURES
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
if: "matrix.ruby == '3.0'"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.6
3.2.7
5 changes: 3 additions & 2 deletions lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
# @param [Hash{Symbol => Object}] options already set
# @return [Array<String>] list of executable commands
# @overload commands(format: :json, **options)
# @param [:json] format (:json)
# Returns commands as JSON, for API usage.
# @param [:json] format
# @param [Hash{Symbol => Object}] options already set
# @return [Array{Object}]
# Returns an array of commands including the command symbol
Expand All @@ -593,7 +594,7 @@ def self.commands(format: nil, **options)
# Subset commands based on filter options
cmds = COMMANDS.reject do |k, c|
c.fetch(:filter, {}).any? do |opt, val|
options[opt].to_s != val.to_s
options.merge(format: format)[opt].to_s != val.to_s
end
end

Expand Down
36 changes: 34 additions & 2 deletions lib/rdf/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module RDF
#
# @example Defining a new RDF serialization format class
# class RDF::NTriples::Format < RDF::Format
# content_type 'application/n-triples', extension: :nt
# content_type 'application/n-triples',
# extension: :nt,
# uri: RDF::URI("http://www.w3.org/ns/formats/N-Triples")
# content_encoding 'utf-8'
#
# reader RDF::NTriples::Reader
Expand Down Expand Up @@ -222,6 +224,19 @@ def self.file_extensions
@@file_extensions
end

##
# Returns the unique URI for the format.
#
# @example retrieving a list of supported file format URIs
#
# RDF::Format.uris.keys
#
# @see https://www.w3.org/ns/formats/
# @return [Hash{Symbol => URI}]
def self.uris
@@uris
end

##
# Returns the set of format symbols for available RDF::Reader subclasses.
#
Expand Down Expand Up @@ -465,6 +480,7 @@ class << self
# @option options [Array<String>] :aliases (nil)
# @option options [Symbol] :extension (nil)
# @option options [Array<Symbol>] :extensions (nil)
# @option options [URI] :uri (nil)
# @return [void]
#
# @overload content_type
Expand Down Expand Up @@ -504,6 +520,10 @@ def self.content_type(type = nil, options = {})
@@content_types[aa] << self unless @@content_types[aa].include?(self)
end
end
# URI identifying this format
if uri = options[:uri]
@@uris[RDF::URI(uri)] = self
end
end
end

Expand All @@ -517,7 +537,7 @@ def self.accept_type
end

##
# Retrieves or defines file extensions for this RDF serialization format.
# Retrieves file extensions for this RDF serialization format.
#
# The return is an array where the first element is the cannonical
# file extension for the format and following elements are alias file extensions.
Expand All @@ -527,6 +547,17 @@ def self.file_extension
@@file_extensions.map {|ext, formats| ext if formats.include?(self)}.compact
end

##
# Retrieves any format URI defined for this format..
#
# @return [URI]
def self.uri
@@uris.invert[self]
end
class << self
alias_method :to_uri, :uri
end

protected

##
Expand Down Expand Up @@ -568,6 +599,7 @@ def self.content_encoding(encoding = nil)
@@readers = {} # @private
@@writers = {} # @private
@@subclasses = [] # @private
@@uris = {} # @private

##
# @private
Expand Down
7 changes: 7 additions & 0 deletions lib/rdf/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class URI
IRI = Regexp.compile("^#{SCHEME}:(?:#{IHIER_PART})(?:\\?#{IQUERY})?(?:\\##{IFRAGMENT})?$").freeze

# Split an IRI into it's component parts
# scheme, authority, path, query, fragment
IRI_PARTS = /^(?:([^:\/?#]+):)?(?:\/\/([^\/?#]*))?([^?#]*)(\?[^#]*)?(#.*)?$/.freeze

# Remove dot expressions regular expressions
Expand Down Expand Up @@ -872,6 +873,12 @@ def parse(value)
parts = {}
if matchdata = IRI_PARTS.match(value)
scheme, authority, path, query, fragment = matchdata[1..-1]

if Gem.win_platform? && scheme && !authority && scheme.match?(/^[a-zA-Z]$/)
# A drive letter, not a scheme
scheme, path = nil, "#{scheme}:#{path}"
end

userinfo, hostport = authority.to_s.split('@', 2)
hostport, userinfo = userinfo, nil unless hostport
user, password = userinfo.to_s.split(':', 2)
Expand Down
5 changes: 4 additions & 1 deletion lib/rdf/nquads.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ module NQuads
# @see http://www.w3.org/TR/n-quads/
# @since 0.4.0
class Format < RDF::Format
content_type 'application/n-quads', extension: :nq, alias: 'text/x-nquads;q=0.2'
content_type 'application/n-quads',
extension: :nq,
alias: 'text/x-nquads;q=0.2',
uri: RDF::URI("http://www.w3.org/ns/formats/N-Quads")
content_encoding 'utf-8'

reader { RDF::NQuads::Reader }
Expand Down
5 changes: 4 additions & 1 deletion lib/rdf/ntriples/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module RDF::NTriples
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
# @see http://www.w3.org/TR/n-triples/
class Format < RDF::Format
content_type 'application/n-triples', extension: :nt, alias: 'text/plain;q=0.2'
content_type 'application/n-triples',
extension: :nt,
alias: 'text/plain;q=0.2',
uri: RDF::URI("http://www.w3.org/ns/formats/N-Triples")
content_encoding 'utf-8'

reader { RDF::NTriples::Reader }
Expand Down
39 changes: 37 additions & 2 deletions spec/format_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

class RDF::Format::FooFormat < RDF::Format
content_type 'application/test;q=1',
extension: :test
extension: :test,
uri: "http://example.com/ns/formats/Foo"
reader { RDF::NTriples::Reader }
def self.detect(sample)
sample == "foo"
Expand All @@ -16,7 +17,8 @@ def self.to_sym; :foo_bar; end
class RDF::Format::BarFormat < RDF::Format
content_type 'application/test',
extension: :test,
alias: 'application/x-test;q=0.1'
alias: 'application/x-test;q=0.1',
uri: "http://example.com/ns/formats/Bar"
reader { RDF::NTriples::Reader }
def self.detect(sample)
sample == "bar"
Expand Down Expand Up @@ -129,6 +131,16 @@ def self.to_sym; :foo_bar; end
end
end

describe ".uris" do
it "returns accept-types of available readers with quality" do
expect(RDF::Format.accept_types).to include(*%w(
application/n-triples text/plain;q=0.2
application/n-quads text/x-nquads;q=0.2
application/test application/x-test;q=0.1
))
end
end

describe ".writer_symbols" do
it "returns symbols of available writers" do
%i(ntriples nquads).each do |sym|
Expand All @@ -152,6 +164,15 @@ def self.to_sym; :foo_bar; end
end
end

describe ".uris" do
it "matches format classes to URIs" do
RDF::Format.uris.each do |u, c|
expect(u).to be_a(RDF::URI)
expect(c).to respond_to(:content_type)
end
end
end

RDF::Format.each do |format|
context format.name do
subject {format}
Expand All @@ -166,6 +187,20 @@ def self.to_sym; :foo_bar; end
end
end

describe RDF::NTriples::Format do
it "has a format URI" do
expect(described_class.uri).to eql RDF::URI('http://www.w3.org/ns/formats/N-Triples')
expect(described_class.to_uri).to eql RDF::URI('http://www.w3.org/ns/formats/N-Triples')
end
end

describe RDF::NQuads::Format do
it "has a format URI" do
expect(described_class.uri).to eql RDF::URI('http://www.w3.org/ns/formats/N-Quads')
expect(described_class.to_uri).to eql RDF::URI('http://www.w3.org/ns/formats/N-Quads')
end
end

context "Examples" do
require 'rdf/ntriples'
subject {RDF::Format}
Expand Down
2 changes: 1 addition & 1 deletion spec/model_uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@
%w(http://foo/bar# /a) => "<http://foo/a>",
%w(http://foo/bar# #a) => "<http://foo/bar#a>",

%w(http://a/bb/ccc/.. g:h) => "<g:h>",
%w(http://a/bb/ccc/.. gg:h) => "<gg:h>",
%w(http://a/bb/ccc/.. g) => "<http://a/bb/ccc/g>",
%w(http://a/bb/ccc/.. ./g) => "<http://a/bb/ccc/g>",
%w(http://a/bb/ccc/.. g/) => "<http://a/bb/ccc/g/>",
Expand Down
2 changes: 1 addition & 1 deletion spec/ntriples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@
expect(output.string).to eq "#{stmt_string}\n"
end

it "should dump statements to a file" do
it "should dump statements to a file", skip: ('not windows' if Gem.win_platform?) do
require 'tmpdir' # for Dir.tmpdir
writer.dump(graph, filename = File.join(Dir.tmpdir, "test.nt"))
expect(File.read(filename)).to eq "#{stmt_string}\n"
Expand Down

0 comments on commit 2b73d12

Please sign in to comment.