Skip to content

Commit

Permalink
Finish 3.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Jan 1, 2019
2 parents ff69be7 + e46ac35 commit 0dee10d
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 14 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -2,15 +2,16 @@ language: ruby
bundler_args: --without debug
script: "bundle exec rspec spec"
before_install:
- "gem update --system"
- "gem install bundler"
- 'gem update --system --conservative || (gem i "rubygems-update:~>2.7" --no-document && update_rubygems)'
- 'gem update bundler --conservative'
env:
- CI=true
rvm:
- 2.2.2
- 2.3
- 2.4
- 2.5
- 2.6
- jruby
- rbx-3
cache: bundler
Expand Down
6 changes: 0 additions & 6 deletions Gemfile
Expand Up @@ -22,7 +22,6 @@ group :debug do
gem 'psych', platforms: [:mri, :rbx]
gem "redcarpet", platforms: :ruby
gem "byebug", platforms: :mri
gem 'rubinius-debugger', platform: :rbx
gem 'ruby-debug', platform: :jruby
gem 'guard-rspec'
end
Expand All @@ -34,8 +33,3 @@ group :test do
gem 'simplecov', require: false, platform: :mri
gem 'coveralls', require: false, platform: :mri
end

platforms :rbx do
gem 'rubysl', '~> 2.0'
gem 'rubinius', '~> 2.0'
end
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.0.7
3.0.9
13 changes: 9 additions & 4 deletions lib/rdf/util/file.rb
Expand Up @@ -348,9 +348,13 @@ class RemoteDocument < StringIO
attr_reader :content_type

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

# Parameters from Content-Type
# @return {Symbol => String}]
attr_reader :parameters

# Response code
# @return [Integer]
attr_reader :code
Expand Down Expand Up @@ -385,17 +389,18 @@ def initialize(body, options = {})
end
@headers = options.fetch(:headers, {})
@charset = options[:charset].to_s.downcase if options[:charset]
@parameters = {}

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

# Find charset
params.each do |param|
p, v = param.split('=')
next unless p.downcase == 'charset'
@charset ||= v.sub(/^["']?(.*)["']?$/, '\1').downcase
@parameters[p.downcase.to_sym] = v.sub(/^["']?([^"']*)["']?$/, '\1')
@charset ||= @parameters[p.downcase.to_sym].downcase if p.downcase == 'charset'
end
end

Expand Down
18 changes: 18 additions & 0 deletions lib/rdf/writer.rb
Expand Up @@ -151,6 +151,22 @@ def self.options

class << self
alias_method :format_class, :format

##
# 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.
#
# @example rejecting a writer based on a profile
# JSON::LD::Writer.accept?(profile: "http://www.w3.org/ns/json-ld#compacted http://example.org/black-listed")
# # => false
#
# @param [Hash{Symbol => String}] accept_params
# @yield [accept_params] if a block is given, returns the result of evaluating that block
# @yieldparam [Hash{Symbol => String}] accept_params
# @return [Boolean]
# @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
def accept?(accept_params)
block_given? ? yield(accept_params) : true
end
end

##
Expand Down Expand Up @@ -257,6 +273,8 @@ def to_sym
# by all writers)
# @option options [Boolean] :unique_bnodes (false)
# 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}
# @option options [Hash{Symbol => String}] :accept_params
# Parameters from ACCEPT header entry for the media-range matching this writer.
# @yield [writer] `self`
# @yieldparam [RDF::Writer] writer
# @yieldreturn [void]
Expand Down
30 changes: 29 additions & 1 deletion spec/util_file_spec.rb
Expand Up @@ -13,7 +13,7 @@

it "returns Net::HTTP if rest-client is not available" do
hide_const("RestClient")
RDF::Util::File.remove_instance_variable(:@http_adapter)
RDF::Util::File.remove_instance_variable(:@http_adapter) if RDF::Util::File.instance_variable_defined?(:@http_adapter)
RDF::Util::File.http_adapter
expect(RDF::Util::File.http_adapter).to eq RDF::Util::File::NetHttpAdapter
end
Expand Down Expand Up @@ -152,6 +152,34 @@
end
end

describe RDF::Util::File::RemoteDocument do
subject {
described_class.new("body",
headers: {
content_type: %(text/turtle ; charset=UTF-8 ; foo="a B c"),
last_modified: "Thu, 24 Oct 2013 23:46:56 GMT",
etag: "abc123",
location: "http://location.example.org/",
content_encoding: "gzip, identity",
link: %(<http://example.com/foo>; rel="self"),
},
base_uri: "http://base.example.org/",
code: 200
)
}

its(:read) {is_expected.to eq "body"}
its(:base_uri) {is_expected.to eq "http://base.example.org/"}
its(:content_type) {is_expected.to eq "text/turtle"}
its(:charset) {is_expected.to eq "utf-8"}
its(:code) {is_expected.to eq 200}
its(:etag) {is_expected.to eq "abc123"}
its(:parameters) {is_expected.to eq({charset: "UTF-8", foo: "a B c"})}
its(:last_modified) {is_expected.to eq DateTime.parse("Thu, 24 Oct 2013 23:46:56 GMT")}
its(:content_encoding) {is_expected.to eq %w(gzip identity)}
its(:links) {expect(subject.links.to_a).to eq [["http://example.com/foo", [%w(rel self)]]]}
end

context "HTTP Adapters" do
require 'rdf/spec/http_adapter'

Expand Down
9 changes: 9 additions & 0 deletions spec/writer_spec.rb
Expand Up @@ -17,4 +17,13 @@
end
end
end

describe ".accept?" do
it "returns true by default" do
expect(RDF::Writer.accept?({})).to be_truthy
end
it "returns block, if given" do
expect(RDF::Writer.accept?({}) {false}).to be_falsy
end
end
end

0 comments on commit 0dee10d

Please sign in to comment.