Skip to content

Commit

Permalink
Release 2.1.1.
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Dec 11, 2016
2 parents aeb042e + b6cbe93 commit 5eca224
Show file tree
Hide file tree
Showing 42 changed files with 732 additions and 177 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ script: "bundle exec rspec spec"
env:
- CI=true
rvm:
- 2.2.5
- 2.3.1
- 2.2.6
- 2.3.3
- jruby
- rbx
cache: bundler
sudo: false
addons:
code_climate:
repo_token: 5806cc8a21c03f4e2f9d3b9d98d5d9fe084b66243b1dbb27b467dbc795acdcac
matrix:
allow_failures:
- rvm: jruby
- rvm: rbx
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ group :develop do
gem 'rdf-isomorphic', github: "ruby-rdf/rdf-isomorphic", branch: "develop"
gem "rdf-reasoner", github: "ruby-rdf/rdf-reasoner", branch: "develop"
gem "rdf-spec", github: "ruby-rdf/rdf-spec", branch: "develop"
gem "rdf-turtle", github: "ruby-rdf/rdf-turtle", branch: "develop"
gem "rdf-vocab", github: "ruby-rdf/rdf-vocab", branch: "develop"
gem "rdf-xsd", github: "ruby-rdf/rdf-xsd", branch: "develop"

Expand All @@ -27,7 +28,6 @@ group :test do
gem 'fasterer'
gem 'simplecov', require: false, platform: :mri
gem 'coveralls', require: false, platform: :mri
gem "codeclimate-test-reporter", require: false
end

platforms :rbx do
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ This is a pure-Ruby library for working with [Resource Description Framework

[![Gem Version](https://badge.fury.io/rb/rdf.png)](http://badge.fury.io/rb/rdf)
[![Build Status](https://travis-ci.org/ruby-rdf/rdf.png?branch=master)](http://travis-ci.org/ruby-rdf/rdf)
[![Code Climate](https://codeclimate.com/github/ruby-rdf/rdf/badges/gpa.svg)](https://codeclimate.com/github/ruby-rdf/rdf)
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf)
[![Join the chat at https://gitter.im/ruby-rdf/rdf](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/ruby-rdf/rdf?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.1.1
5 changes: 5 additions & 0 deletions dependencyci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
platform:
Rubygems:
rdf-isomorphic:
tests:
unmaintained: skip
14 changes: 14 additions & 0 deletions lib/rdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ def self.[](property)
property.to_s =~ %r{_\d+} ? RDF::URI("#{to_uri}#{property}") : RDF::RDFV[property]
end

##
# Return an enumerator over {RDF::Statement} defined for this vocabulary.
# @return [RDF::Enumerable::Enumerator]
# @see Object#enum_for
def self.enum_for(method = :each_statement, *args)
# Ensure that enumerators are, themselves, queryable
Enumerable::Enumerator.new do |yielder|
RDF::RDFV.send(method, *args) {|*y| yielder << (y.length > 1 ? y : y.first)}
end
end
class << self
alias_method :to_enum, :enum_for
end

##
# respond to module or RDFV
def self.respond_to?(method, include_all = false)
Expand Down
4 changes: 3 additions & 1 deletion lib/rdf/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,9 @@ def self.parse(files, options = {}, &block)
# If files are empty, either use options[:execute]
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : $stdin
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
RDF::Reader.for(options[:format] || :ntriples).new(input, options) do |reader|
r = RDF::Reader.for(options[:format] || :ntriples)
(@readers ||= []) << r
r.new(input, options) do |reader|
yield(reader)
end
else
Expand Down
40 changes: 38 additions & 2 deletions lib/rdf/format.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ def self.reader_types
reader_symbols.flat_map {|s| RDF::Format.for(s).content_type}.uniq
end

##
# Returns the set of content types with quality for available RDF::Reader subclasses.
#
# @example
#
# accept_types = RDF::Format.accept_types
# # => %w(text/html;q=0.5 text/turtle ...)
#
# @return [Array<String>]
def self.accept_types
reader_symbols.flat_map {|s| RDF::Format.for(s).accept_type}.uniq
end

##
# Returns the set of format symbols for available RDF::Writer subclasses.
#
Expand Down Expand Up @@ -400,6 +413,11 @@ class << self
# extensions, that should be mapped to the given MIME type and handled
# by this class.
#
# Optionally, both `type`, `alias`, and `aliases`, may be parameterized
# for expressing quality.
#
# content_type "text/html;q=0.4"
#
# @param [String] type
# @param [Hash{Symbol => Object}] options
# @option options [String] :alias (nil)
Expand All @@ -420,10 +438,14 @@ def self.content_type(type = nil, options = {})
[@@content_type[self], @@content_types.map {
|ct, cl| (cl.include?(self) && ct != @@content_type[self]) ? ct : nil }].flatten.compact
else
accept_type, type = type, type.split(';').first
@@content_type[self] = type
@@content_types[type] ||= []
@@content_types[type] << self unless @@content_types[type].include?(self)

@@accept_types[accept_type] ||= []
@@accept_types[accept_type] << self unless @@accept_types[accept_type].include?(self)

if extensions = (options[:extension] || options[:extensions])
extensions = Array(extensions).map(&:to_sym)
extensions.each do |ext|
Expand All @@ -433,13 +455,26 @@ def self.content_type(type = nil, options = {})
end
if aliases = (options[:alias] || options[:aliases])
aliases = Array(aliases).each do |a|
@@content_types[a] ||= []
@@content_types[a] << self unless @@content_types[a].include?(self)
aa = a.split(';').first
@@accept_types[a] ||= []
@@accept_types[a] << self unless @@accept_types[a].include?(self)

@@content_types[aa] ||= []
@@content_types[aa] << self unless @@content_types[aa].include?(self)
end
end
end
end

##
# Returns an array of values appropriate for an Accept header.
# Same as `self.content_type`, if no parameter is given when defined.
#
# @return [Array<String>]
def self.accept_type
@@accept_types.map {|t, formats| t if formats.include?(self)}.compact
end

##
# Retrieves or defines file extensions for this RDF serialization format.
#
Expand Down Expand Up @@ -488,6 +523,7 @@ def self.content_encoding(encoding = nil)
@@content_type = {} # @private
@@content_types = {} # @private
@@content_encoding = {} # @private
@@accept_types = {} # @private
@@readers = {} # @private
@@writers = {} # @private
@@subclasses = [] # @private
Expand Down
5 changes: 1 addition & 4 deletions lib/rdf/mixin/enumerator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@ class Enumerator < ::Enumerator
include Queryable
include Enumerable

def method_missing(method, *args)
self.to_a if method.to_sym == :to_ary
end

# Make sure returned arrays are also queryable
def to_a
return super.to_a.extend(RDF::Queryable, RDF::Enumerable)
end
alias_method :to_ary, :to_a
end
end

Expand Down
110 changes: 100 additions & 10 deletions lib/rdf/model/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,83 @@ module RDF
##
# An RDF Dataset
#
# Datasets are immutable by default. {RDF::Repository} provides an interface
# Datasets are immutable by default. {RDF::Repository} provides an interface
# for mutable Datasets.
#
#
# A Dataset functions as an a set of named RDF graphs with a default graph.
# It implements {RDF::Enumerable} and {RDF::Queryable} over the whole set;
# if no specific graph name is queried, enumerating and querying takes place
# over the intersection of all the graphs in the Dataset.
#
# The default graph is named with a constant `DEFAULT_GRAPH`.
#
# @example initializing an RDF::Dataset with existing data
# statements = [RDF::Statement.new(RDF::URI(:s), RDF::URI(:p), :o)]
# dataset = RDF::Dataset.new(statements: statements)
# dataset.count # => 1
#
# @see https://www.w3.org/TR/rdf11-concepts/#section-dataset
# @see https://www.w3.org/TR/rdf11-datasets/
class Dataset
include RDF::Countable
include RDF::Enumerable
include RDF::Durable
include RDF::Queryable

ISOLATION_LEVELS = [ :read_uncommitted,
:read_committed,
:repeatable_read,
:snapshot,
:serializable].freeze
DEFAULT_GRAPH = false

ISOLATION_LEVELS = [ :read_uncommitted,
:read_committed,
:repeatable_read,
:snapshot,
:serializable ].freeze

##
# @param [RDF::Enumerable, Array<RDF::Statement>] statements the initial
# contents of the dataset
# @yield [dataset] yields itself when a block is given
# @yieldparam [RDF::Dataset] dataset
def initialize(statements: [], **options, &block)
@statements = statements.map do |s|
s = s.dup
s.graph_name ||= DEFAULT_GRAPH
s.freeze
end.freeze

if block_given?
case block.arity
when 1 then yield self
else instance_eval(&block)
end
end
end

##
# @private
# @see RDF::Durable#durable?
def durable?
false
end

##
# @private
# @see RDF::Enumerable#each_statement
def each_statement
if block_given?
@statements.each do |st|
if st.graph_name.equal?(DEFAULT_GRAPH)
st = st.dup
st.graph_name = nil
end

yield st
end

self
end

enum_statement
end
alias_method :each, :each_statement

##
# Returns a developer-friendly representation of this object.
Expand All @@ -36,13 +97,42 @@ def inspect!
each_statement { |statement| statement.inspect! }
nil
end

##
# @return [Symbol] a representation of the isolation level for reads of this
# Dataset. One of `:read_uncommitted`, `:read_committed`, `:repeatable_read`,
# Dataset. One of `:read_uncommitted`, `:read_committed`, `:repeatable_read`,
# `:snapshot`, or `:serializable`.
def isolation_level
:read_committed
end

##
# @private
# @see RDF::Enumerable#supports?
def supports?(feature)
return true if feature == :graph_name
super
end

protected

##
# Implements basic query pattern matching over the Dataset, with handling
# for a default graph.
def query_pattern(pattern, options = {}, &block)
return super unless pattern.graph_name == DEFAULT_GRAPH

if block_given?
pattern = pattern.dup
pattern.graph_name = nil

each_statement do |statement|
yield statement if (statement.graph_name == DEFAULT_GRAPH ||
statement.graph_name.nil?) && pattern === statement
end
else
enum_for(:query_pattern, pattern, options)
end
end
end
end
24 changes: 24 additions & 0 deletions lib/rdf/model/literal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,30 @@ def canonicalize!
self
end

##
# Returns the literal, first removing all whitespace on both ends of the value, and then changing remaining consecutive whitespace groups into one space each.
#
# Note that it handles both ASCII and Unicode whitespace.
#
# @see [String#squish](http://apidock.com/rails/String/squish)
# @return [RDF::Literal] a new literal based on `self`.
def squish(*other_string)
self.dup.squish!
end

##
# Performs a destructive {#squish}.
#
# @see [String#squish!](http://apidock.com/rails/String/squish%21)
# @return self
def squish!
@string = value.
gsub(/\A[[:space:]]+/, '').
gsub(/[[:space:]]+\z/, '').
gsub(/[[:space:]]+/, ' ')
self
end

##
# Escape a literal using ECHAR escapes.
#
Expand Down
2 changes: 1 addition & 1 deletion lib/rdf/model/literal/double.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module RDF; class Literal
# @since 0.2.1
class Double < Numeric
DATATYPE = RDF::XSD.double
GRAMMAR = /^(?:NaN|(?:[\+\-]?(?:INF|(?:\d+(\.\d*)?([eE][\+\-]?\d+)?))))$/.freeze
GRAMMAR = /^(?:NaN|(?:[\+\-]?(?:INF|(?:\d+(\.\d*)?(e[\+\-]?\d+)?))))$/i.freeze

##
# @param [Float, #to_f] value
Expand Down
3 changes: 1 addition & 2 deletions lib/rdf/model/literal/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ def initialize(value, options = {})
@string = options[:lexical] if options.has_key?(:lexical)
@string ||= value if value.is_a?(String)
@object = case
when value.is_a?(::String) then Integer(value) rescue nil
when value.is_a?(::Integer) then value
when value.respond_to?(:to_i) then value.to_i
when value.is_a?(::Integer) then value
else Integer(value.to_s) rescue nil
end
end
Expand Down

0 comments on commit 5eca224

Please sign in to comment.