Skip to content

Commit

Permalink
Finish 3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Mar 21, 2018
2 parents 7c7ad14 + a87d57b commit ff729b0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1
3.0.2
4 changes: 3 additions & 1 deletion lib/rdf/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def canonicalize!
# @see <http://tools.ietf.org/html/rfc3986#section-5.2>
# @see RDF::URI#/
# @see RDF::URI#+
# @param [Array<String, RDF::URI, #to_s>] uris
# @param [Array<String, RDF::URI, #to_s>] uris absolute or relative URIs.
# @return [RDF::URI]
# @see http://tools.ietf.org/html/rfc3986#section-5.2.2
# @see http://tools.ietf.org/html/rfc3986#section-5.2.3
Expand Down Expand Up @@ -458,6 +458,8 @@ def join(*uris)
# this method does not perform any normalization, removal of spurious
# paths, or removal of parent directory references `(/../)`.
#
# When `fragment` is a path segment containing a colon, best practice is to prepend a `./` and use {#join}, which resolves dot-segments.
#
# See also `#+`, which concatenates the string forms of two URIs without
# any sort of checking or processing.
#
Expand Down
4 changes: 3 additions & 1 deletion lib/rdf/reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def self.open(filename, format: nil, **options, &block)

Util::File.open_file(filename, options) do |file|
format_options = options.dup
format_options[:content_type] ||= file.content_type if file.respond_to?(:content_type)
format_options[:content_type] ||= file.content_type if
file.respond_to?(:content_type) &&
!file.content_type.to_s.include?('text/plain')
format_options[:file_name] ||= filename
reader = if self == RDF::Reader
# We are the abstract reader class, find an appropriate reader
Expand Down
11 changes: 11 additions & 0 deletions lib/rdf/vocab/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ def serialize_value(value, key, indent: "")
value.to_ruby(indent: indent + " ")
elsif value.is_a?(RDF::Term)
"#{value.to_s.inspect}.freeze"
elsif value.is_a?(RDF::List)
list_elements = value.map do |u|
if u.uri?
"#{u.pname.inspect}.freeze"
elsif u.respond_to?(:to_ruby)
u.to_ruby(indent: indent + " ")
else
"#{u.to_s.inspect}.freeze"
end
end
"list(#{list_elements.join(', ')})"
else
"#{value.inspect}.freeze"
end
Expand Down
6 changes: 5 additions & 1 deletion lib/rdf/vocabulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@ def from_graph(graph, url: nil, class_name: nil, extra: nil)
else statement.predicate.pname.to_sym
end

# Skip literals other than plain or english
# This is because the ruby representation does not preserve language
next if statement.object.literal? && (statement.object.language || :en).to_s !~ /^en-?/

(term[key] ||= []) << statement.object
end

Expand Down Expand Up @@ -1080,7 +1084,7 @@ def to_ruby(indent: "")
"term(" +
(self.uri? ? self.to_s.inspect + ",\n" : "\n") +
"#{indent} " +
attributes.keys.map do |k|
attributes.keys.sort.map do |k|
values = attribute_value(k)
values = [values].compact unless values.is_a?(Array)
values = values.map do |value|
Expand Down
15 changes: 15 additions & 0 deletions spec/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,20 @@
reader_mock.got_here
end
end

it "ignores content type 'text/plain'" do
uri = "http://example/foo.ttl"
accept = (RDF::Format.accept_types + %w(*/*;q=0.1)).join(", ")
reader_mock = double("reader")
expect(reader_mock).to receive(:got_here)
WebMock.
stub_request(:get, uri).
to_return(body: "foo", status: 200, headers: { 'Content-Type' => 'text/plain'})

described_class.open(uri) do |r|
expect(r).to be_a(RDF::Turtle::Reader)
reader_mock.got_here
end
end
end
end

0 comments on commit ff729b0

Please sign in to comment.