Skip to content

Commit 0dee10d

Browse files
committed
Finish 3.0.9
2 parents ff69be7 + e46ac35 commit 0dee10d

File tree

7 files changed

+69
-14
lines changed

7 files changed

+69
-14
lines changed

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ language: ruby
22
bundler_args: --without debug
33
script: "bundle exec rspec spec"
44
before_install:
5-
- "gem update --system"
6-
- "gem install bundler"
5+
- 'gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)'
6+
- 'gem update bundler --conservative'
77
env:
88
- CI=true
99
rvm:
1010
- 2.2.2
1111
- 2.3
1212
- 2.4
1313
- 2.5
14+
- 2.6
1415
- jruby
1516
- rbx-3
1617
cache: bundler

Gemfile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ group :debug do
2222
gem 'psych', platforms: [:mri, :rbx]
2323
gem "redcarpet", platforms: :ruby
2424
gem "byebug", platforms: :mri
25-
gem 'rubinius-debugger', platform: :rbx
2625
gem 'ruby-debug', platform: :jruby
2726
gem 'guard-rspec'
2827
end
@@ -34,8 +33,3 @@ group :test do
3433
gem 'simplecov', require: false, platform: :mri
3534
gem 'coveralls', require: false, platform: :mri
3635
end
37-
38-
platforms :rbx do
39-
gem 'rubysl', '~> 2.0'
40-
gem 'rubinius', '~> 2.0'
41-
end

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.7
1+
3.0.9

lib/rdf/util/file.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,13 @@ class RemoteDocument < StringIO
348348
attr_reader :content_type
349349

350350
# Encoding of resource (from Content-Type), downcased. Also applied to content if it is UTF
351-
# @return [String}]
351+
# @return [String]
352352
attr_reader :charset
353353

354+
# Parameters from Content-Type
355+
# @return {Symbol => String}]
356+
attr_reader :parameters
357+
354358
# Response code
355359
# @return [Integer]
356360
attr_reader :code
@@ -385,17 +389,18 @@ def initialize(body, options = {})
385389
end
386390
@headers = options.fetch(:headers, {})
387391
@charset = options[:charset].to_s.downcase if options[:charset]
392+
@parameters = {}
388393

389-
# Find Content-Type
394+
# Find Content-Type and extract other parameters
390395
if headers[:content_type]
391396
ct, *params = headers[:content_type].split(';').map(&:strip)
392397
@content_type ||= ct
393398

394399
# Find charset
395400
params.each do |param|
396401
p, v = param.split('=')
397-
next unless p.downcase == 'charset'
398-
@charset ||= v.sub(/^["']?(.*)["']?$/, '\1').downcase
402+
@parameters[p.downcase.to_sym] = v.sub(/^["']?([^"']*)["']?$/, '\1')
403+
@charset ||= @parameters[p.downcase.to_sym].downcase if p.downcase == 'charset'
399404
end
400405
end
401406

lib/rdf/writer.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,22 @@ def self.options
151151

152152
class << self
153153
alias_method :format_class, :format
154+
155+
##
156+
# Use parameters from accept-params to determine if the parameters are acceptable to invoke this writer. The `accept_params` will subsequently be provided to the writer instance.
157+
#
158+
# @example rejecting a writer based on a profile
159+
# JSON::LD::Writer.accept?(profile: "http://www.w3.org/ns/json-ld#compacted http://example.org/black-listed")
160+
# # => false
161+
#
162+
# @param [Hash{Symbol => String}] accept_params
163+
# @yield [accept_params] if a block is given, returns the result of evaluating that block
164+
# @yieldparam [Hash{Symbol => String}] accept_params
165+
# @return [Boolean]
166+
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
167+
def accept?(accept_params)
168+
block_given? ? yield(accept_params) : true
169+
end
154170
end
155171

156172
##
@@ -257,6 +273,8 @@ def to_sym
257273
# by all writers)
258274
# @option options [Boolean] :unique_bnodes (false)
259275
# Use unique {Node} identifiers, defaults to using the identifier which the node was originall initialized with (if any). Implementations should ensure that Nodes are serialized using a unique representation independent of any identifier used when creating the node. See {NTriples::Writer#format_node}
276+
# @option options [Hash{Symbol => String}] :accept_params
277+
# Parameters from ACCEPT header entry for the media-range matching this writer.
260278
# @yield [writer] `self`
261279
# @yieldparam [RDF::Writer] writer
262280
# @yieldreturn [void]

spec/util_file_spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
it "returns Net::HTTP if rest-client is not available" do
1515
hide_const("RestClient")
16-
RDF::Util::File.remove_instance_variable(:@http_adapter)
16+
RDF::Util::File.remove_instance_variable(:@http_adapter) if RDF::Util::File.instance_variable_defined?(:@http_adapter)
1717
RDF::Util::File.http_adapter
1818
expect(RDF::Util::File.http_adapter).to eq RDF::Util::File::NetHttpAdapter
1919
end
@@ -152,6 +152,34 @@
152152
end
153153
end
154154

155+
describe RDF::Util::File::RemoteDocument do
156+
subject {
157+
described_class.new("body",
158+
headers: {
159+
content_type: %(text/turtle ; charset=UTF-8 ; foo="a B c"),
160+
last_modified: "Thu, 24 Oct 2013 23:46:56 GMT",
161+
etag: "abc123",
162+
location: "http://location.example.org/",
163+
content_encoding: "gzip, identity",
164+
link: %(<http://example.com/foo>; rel="self"),
165+
},
166+
base_uri: "http://base.example.org/",
167+
code: 200
168+
)
169+
}
170+
171+
its(:read) {is_expected.to eq "body"}
172+
its(:base_uri) {is_expected.to eq "http://base.example.org/"}
173+
its(:content_type) {is_expected.to eq "text/turtle"}
174+
its(:charset) {is_expected.to eq "utf-8"}
175+
its(:code) {is_expected.to eq 200}
176+
its(:etag) {is_expected.to eq "abc123"}
177+
its(:parameters) {is_expected.to eq({charset: "UTF-8", foo: "a B c"})}
178+
its(:last_modified) {is_expected.to eq DateTime.parse("Thu, 24 Oct 2013 23:46:56 GMT")}
179+
its(:content_encoding) {is_expected.to eq %w(gzip identity)}
180+
its(:links) {expect(subject.links.to_a).to eq [["http://example.com/foo", [%w(rel self)]]]}
181+
end
182+
155183
context "HTTP Adapters" do
156184
require 'rdf/spec/http_adapter'
157185

spec/writer_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@
1717
end
1818
end
1919
end
20+
21+
describe ".accept?" do
22+
it "returns true by default" do
23+
expect(RDF::Writer.accept?({})).to be_truthy
24+
end
25+
it "returns block, if given" do
26+
expect(RDF::Writer.accept?({}) {false}).to be_falsy
27+
end
28+
end
2029
end

0 commit comments

Comments
 (0)