Skip to content

Commit

Permalink
Finish 3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Oct 15, 2018
2 parents 4a7a92d + 65b7a33 commit 52109c1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ before_install:
env:
- CI=true
rvm:
- 2.2
- 2.2.2
- 2.3
- 2.4
- 2.5
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.4
3.0.5
4 changes: 2 additions & 2 deletions lib/rdf/vocabulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def from_graph(graph, url: nil, class_name: nil, extra: nil)
term_defs.each do |term, attributes|
# Turn embedded BNodes into either their Term definition or a List
attributes.each do |ak, avs|
attributes[ak] = avs.is_a?(Array) ? avs.map do |av|
attributes[ak] = avs.is_a?(Array) ? (avs.map do |av|
l = RDF::List.new(subject: av, graph: graph)
if l.valid?
RDF::List.new(subject: av) do |nl|
Expand All @@ -547,7 +547,7 @@ def from_graph(graph, url: nil, class_name: nil, extra: nil)
else
av
end
end.compact : avs
end).compact : avs
end

if term == :""
Expand Down
40 changes: 15 additions & 25 deletions lib/rdf/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,29 +158,22 @@ class << self
# the graph or repository to dump
# @param [IO, File, String] io
# the output stream or file to write to
# @param [Encoding, String, Symbol] encoding
# the encoding to use on the output stream.
# Defaults to the format associated with `content_encoding`.
# @param [Hash{Symbol => Object}] options
# passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
# @return [void]
def self.dump(data, io = nil, encoding: nil, **options)
if io.is_a?(String)
io = File.open(io, 'w')
elsif io.respond_to?(:external_encoding) && io.external_encoding
encoding ||= io.external_encoding
end
io.set_encoding(encoding) if io.respond_to?(:set_encoding) && encoding
def self.dump(data, io = nil, **options)
io = File.open(io, 'w') if io.is_a?(String)
method = data.respond_to?(:each_statement) ? :each_statement : :each
if io
new(io, encoding: encoding, **options) do |writer|
new(io, **options) do |writer|
io.set_encoding(writer.encoding) if io.respond_to?(:set_encoding)
data.send(method) do |statement|
writer << statement
end
writer.flush
end
else
buffer(encoding: encoding, **options) do |writer|
buffer(**options) do |writer|
data.send(method) do |statement|
writer << statement
end
Expand All @@ -191,23 +184,21 @@ def self.dump(data, io = nil, encoding: nil, **options)
##
# Buffers output into a string buffer.
#
# @param [Encoding, String, Symbol] encoding
# the encoding to use on the output stream.
# Defaults to the format associated with `content_encoding`.
# @param [Hash{Symbol => Object}] options
# passed to {RDF::Writer#initialize}
# @yield [writer]
# @yieldparam [RDF::Writer] writer
# @yieldreturn [void]
# @return [String]
# @raise [ArgumentError] if no block is provided
def self.buffer(*args, encoding: nil, **options, &block)
encoding ||= Encoding::UTF_8 if RUBY_PLATFORM == "java"
def self.buffer(*args, **options, &block)
raise ArgumentError, "block expected" unless block_given?

StringIO.open do |buffer|
buffer.set_encoding(encoding) if encoding
self.new(buffer, *args, encoding: encoding, **options) { |writer| block.call(writer) }
self.new(buffer, *args, **options) do |writer|
buffer.set_encoding(writer.encoding)
block.call(writer)
end
buffer.string
end
end
Expand All @@ -216,19 +207,18 @@ def self.buffer(*args, encoding: nil, **options, &block)
# Writes output to the given `filename`.
#
# @param [String, #to_s] filename
# @param [Encoding, String, Symbol] encoding
# the encoding to use on the output stream.
# Defaults to the format associated with `content_encoding`.
# @param [Symbol] format (nil)
# @param [Hash{Symbol => Object}] options
# any additional options (see {RDF::Writer#initialize} and {RDF::Format.for})
# @return [RDF::Writer]
def self.open(filename, encoding: nil, format: nil, **options, &block)
def self.open(filename, format: nil, **options, &block)
File.open(filename, 'wb') do |file|
file.set_encoding(encoding) if encoding
format_options = options.dup
format_options[:file_name] ||= filename
self.for(format || format_options).new(file, encoding: encoding, **options, &block)
self.for(format || format_options).new(file, **options) do |writer|
file.set_encoding(writer.encoding)
block.call(writer)
end
end
end

Expand Down
7 changes: 0 additions & 7 deletions spec/ntriples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,6 @@
s = writer.dump(graph, output, encoding: encoding)
expect(output.external_encoding).to eq encoding
end

it "takes encoding from file external_encoding" do
output = StringIO.new
output.set_encoding encoding
s = writer.dump(graph, output)
expect(output.external_encoding).to eq encoding
end
end
end

Expand Down
6 changes: 6 additions & 0 deletions spec/vocabulary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@
property :Class
property :prop
property :prop2, label: "Test property label", comment: " Test property comment"
property :snake_case
end
end

Expand All @@ -272,6 +273,11 @@
.to eq (test_vocab.to_uri / 'aMissingMethod')
end

it "does not camelize if snake-case term found" do
expect(test_vocab.snake_case).to be_a(RDF::Vocabulary::Term)
expect(test_vocab.snake_case).to eq (test_vocab.to_uri / 'snake_case')
end

it "should respond to [] with properties that have been defined" do
expect(test_vocab[:prop]).to be_a(RDF::URI)
expect(test_vocab["prop2"]).to be_a(RDF::URI)
Expand Down

0 comments on commit 52109c1

Please sign in to comment.