Skip to content

Commit e6800d0

Browse files
committed
Finish 3.1.8
2 parents 53f46cc + d04a222 commit e6800d0

27 files changed

Lines changed: 326 additions & 161 deletions

.coveralls.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
repo_token: n1Ae6aLVyChERzltBHnuNg7YREyRseSlp

.github/workflows/ci.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow runs continuous CI across different versions of ruby on all branches and pull requests to develop.
2+
3+
name: CI
4+
5+
# Controls when the action will run.
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the develop branch
8+
push:
9+
branches: [ '**' ]
10+
pull_request:
11+
branches: [ develop ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
17+
jobs:
18+
# This workflow contains a single job called "build"
19+
tests:
20+
name: Ruby ${{ matrix.ruby }}
21+
if: "contains(github.event.commits[0].message, '[ci skip]') == false"
22+
runs-on: ubuntu-latest
23+
env:
24+
CI: true
25+
ALLOW_FAILURES: false # ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'jruby' }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
ruby:
30+
- 2.4
31+
- 2.5
32+
- 2.6
33+
- 2.7
34+
- 3.0
35+
- ruby-head
36+
- jruby
37+
steps:
38+
- name: Clone repository
39+
uses: actions/checkout@v2
40+
- name: Set up Ruby
41+
uses: ruby/setup-ruby@v1
42+
with:
43+
ruby-version: ${{ matrix.ruby }}
44+
- name: Install dependencies
45+
run: bundle install --jobs 4 --retry 3
46+
- name: Run tests
47+
run: bundle exec rspec spec || $ALLOW_FAILURES
48+

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ rvm:
77
- 2.5
88
- 2.6
99
- 2.7
10+
- ruby-head
1011
- jruby
1112
cache: bundler
1213
sudo: false
1314
matrix:
1415
allow_failures:
1516
- rvm: jruby
17+
- rvm: ruby-head
1618
dist: trusty

Gemfile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ group :develop do
2222
end
2323

2424
group :debug do
25-
gem 'psych', platforms: [:mri, :rbx]
2625
gem "redcarpet", platforms: :ruby
2726
gem "byebug", platforms: :mri
2827
gem 'guard-rspec'
@@ -33,6 +32,6 @@ group :test do
3332
gem "rake"
3433
gem "equivalent-xml"
3534
gem 'fasterer'
36-
gem 'simplecov', platforms: :mri
37-
gem 'coveralls', '~> 0.8', platforms: :mri
35+
gem 'simplecov', require: false, platforms: :mri
36+
gem 'coveralls', require: false, platforms: :mri
3837
end

README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ This is a pure-Ruby library for working with [Resource Description Framework
66
* <https://ruby-rdf.github.com/rdf>
77

88
[![Gem Version](https://badge.fury.io/rb/rdf.png)](https://badge.fury.io/rb/rdf)
9-
[![Build Status](https://travis-ci.org/ruby-rdf/rdf.png?branch=master)](https://travis-ci.org/ruby-rdf/rdf)
10-
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/r/ruby-rdf/rdf)
11-
[![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)
9+
[![Build Status](https://github.com/ruby-rdf/rdf/workflows/CI/badge.svg?branch=develop)](https://github.com/ruby-rdf/rdf/actions?query=workflow%3ACI)
10+
[![Coverage Status](https://coveralls.io/repos/ruby-rdf/rdf/badge.svg)](https://coveralls.io/github/ruby-rdf/rdf)
11+
[![Gitter chat](https://badges.gitter.im/ruby-rdf/rdf.png)](https://gitter.im/ruby-rdf/rdf)
1212

1313
## Features
1414

@@ -39,6 +39,22 @@ resources. Clients may also consider using [RestClient Components][] to enable
3939
client-side caching of HTTP results using [Rack::Cache][] or other Rack
4040
middleware.
4141

42+
See {RDF::Util::File} for configuring other mechanisms for retrieving resources.
43+
44+
### Term caching and configuration.
45+
46+
RDF.rb uses a weak-reference cache for storing internalized versions of URIs and Nodes. This is particularly useful for Nodes as two nodes are equivalent only if they're the same node.
47+
48+
By default, each cache can grow to an unlimited size, but this can be configured using {RDF.config}, for general limits, along with URI- or Node-specific limits.
49+
50+
For example, to limit the size of the URI intern cache only:
51+
52+
RDF.config.uri_cache_size = 10_000
53+
54+
The default for creating new caches without a specific initialization size can be set using:
55+
56+
RDF.config.cache_size = 100_000
57+
4258
## Differences between RDF 1.0 and RDF 1.1
4359

4460
This version of RDF.rb is fully compatible with [RDF 1.1][], but it creates some
@@ -246,17 +262,10 @@ By default, the N-Triples reader will reject a document containing a subject res
246262
end
247263
# => RDF::ReaderError
248264

249-
Readers support a `rdfstar` option with either `:PG` (Property Graph) or `:SA` (Separate Assertions) modes. In `:PG` mode, statements that are used in the subject or object positions are also implicitly added to the graph:
250-
251-
graph = RDF::Graph.new do |graph|
252-
RDF::NTriples::Reader.new(nt, rdfstar: :PG) {|reader| graph << reader}
253-
end
254-
graph.count #=> 2
255-
256-
When using the `:SA` mode, only one statement is asserted, although the reified statement is contained within the graph.
265+
Readers support a boolean valued `rdfstar` option.
257266

258267
graph = RDF::Graph.new do |graph|
259-
RDF::NTriples::Reader.new(nt, rdfstar: :SA) {|reader| graph << reader}
268+
RDF::NTriples::Reader.new(nt, rdfstar: true) {|reader| graph << reader}
260269
end
261270
graph.count #=> 1
262271

@@ -478,7 +487,7 @@ see <https://unlicense.org/> or the accompanying {file:UNLICENSE} file.
478487
[RDF::TriX]: https://ruby-rdf.github.com/rdf-trix
479488
[RDF::Turtle]: https://ruby-rdf.github.com/rdf-turtle
480489
[RDF::Raptor]: https://ruby-rdf.github.com/rdf-raptor
481-
[RDF*]: https://lists.w3.org/Archives/Public/public-rdf-star/
490+
[RDF*]: https://w3c.github.io/rdf-star/rdf-star-cg-spec.html
482491
[LinkedData]: https://ruby-rdf.github.com/linkeddata
483492
[JSON::LD]: https://ruby-rdf.github.com/json-ld
484493
[RestClient]: https://rubygems.org/gems/rest-client

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.7
1+
3.1.8

lib/rdf.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require 'bigdecimal'
33
require 'date'
44
require 'time'
5+
require "ostruct"
56

67
require 'rdf/version'
78
require 'rdf/extensions'
@@ -79,6 +80,29 @@ module RDF
7980
# CLI
8081
autoload :CLI, 'rdf/cli'
8182

83+
##
84+
# Configuration, used open for configuring constants used within the codebase.
85+
#
86+
# @example set default cache size to be at most 10,000 entries
87+
#
88+
# RDF.config.cache_size = 10_000
89+
#
90+
# @example set cache size for interned URIs to 5,000 entries
91+
#
92+
# RDF.config.uri_cache_size = 5_000
93+
#
94+
# Defaults:
95+
# * `cache_size`: -1
96+
# * `uri_cache_size`: `cache_size`
97+
# * `node_cache_size`: `cache_size`
98+
#
99+
# @note cache configurations must be set before initial use, when the caches are allocated.
100+
# @see RDF::Util::Cache.new
101+
# @return [Object]
102+
def self.config
103+
@config ||= OpenStruct.new(cache_size: -1, uri_cache_size: nil, node_cache_size: nil)
104+
end
105+
82106
##
83107
# Alias for `RDF::Resource.new`.
84108
#

lib/rdf/cli.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def to_hash
162162
# * `lambda` code run to execute command.
163163
# * `filter` Option values that must match for command to be used
164164
# * `control` Used to indicate how (if) command is displayed
165+
# * `repository` Use this repository, if set
165166
# * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
166167
# * `option_use`: A hash of option symbol to option usage, used for overriding the default status of an option for this command.
167168
# @return [Hash{Symbol => Hash{Symbol => Object}}]
@@ -493,6 +494,9 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
493494
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
494495
end
495496
end
497+
498+
# The command may specify a repository instance to use
499+
options[:repository] ||= COMMANDS[c.to_sym][:repository]
496500
end
497501

498502
# Hacks for specific options
@@ -501,9 +505,11 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
501505
options[:format] = options[:format].to_sym if options[:format]
502506
options[:output_format] = options[:output_format].to_sym if options[:output_format]
503507

504-
@repository = options[:ordered] ?
505-
[].extend(RDF::Enumerable, RDF::Queryable) :
506-
RDF::Repository.new
508+
# Allow repository to be set via option.
509+
@repository = options[:repository] ||
510+
(options[:ordered] ?
511+
[].extend(RDF::Enumerable, RDF::Queryable) :
512+
RDF::Repository.new)
507513

508514
# Parse input files if any command requires it
509515
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
@@ -518,7 +524,10 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
518524

519525
# Run each command in sequence
520526
cmds.each do |command|
521-
COMMANDS[command.to_sym][:lambda].call(args, output: output, **options.merge(messages: messages))
527+
COMMANDS[command.to_sym][:lambda].call(args,
528+
output: output,
529+
messages: messages,
530+
**options.merge(repository: repository))
522531
end
523532

524533
# Normalize messages

lib/rdf/model/list.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,23 @@ def self.[](*values)
4949
# g = RDF::Graph.new << l
5050
# g.count # => l.count
5151
#
52+
# @example use a transaction for block initialization
53+
# l = RDF::List(graph: graph, wrap_transaction: true) do |list|
54+
# list << RDF::Literal(1)
55+
# # list.graph.rollback will rollback all list changes within this block.
56+
# end
57+
# list.count #=> 1
58+
#
5259
# @param [RDF::Resource] subject (RDF.nil)
5360
# Subject should be an {RDF::Node}, not a {RDF::URI}. A list with an IRI head will not validate, but is commonly used to detect if a list is valid.
5461
# @param [RDF::Graph] graph (RDF::Graph.new)
5562
# @param [Array<RDF::Term>] values
5663
# Any values which are not terms are coerced to `RDF::Literal`.
64+
# @param [Boolean] wrap_transaction (false)
65+
# Wraps the callback in a transaction, and replaces the graph with that transaction for the duraction of the callback. This has the effect of allowing any list changes to be made atomically, or rolled back.
5766
# @yield [list]
5867
# @yieldparam [RDF::List] list
59-
def initialize(subject: nil, graph: nil, values: nil, &block)
68+
def initialize(subject: nil, graph: nil, values: nil, wrap_transaction: false, &block)
6069
@subject = subject || RDF.nil
6170
@graph = graph || RDF::Graph.new
6271
is_empty = @graph.query({subject: subject, predicate: RDF.first}).empty?
@@ -78,9 +87,25 @@ def initialize(subject: nil, graph: nil, values: nil, &block)
7887
end
7988

8089
if block_given?
81-
case block.arity
82-
when 1 then block.call(self)
83-
else instance_eval(&block)
90+
if wrap_transaction
91+
old_graph = @graph
92+
begin
93+
Transaction.begin(@graph, graph_name: @graph.graph_name, mutable: @graph.mutable?) do |trans|
94+
@graph = trans
95+
case block.arity
96+
when 1 then block.call(self)
97+
else instance_eval(&block)
98+
end
99+
trans.execute if trans.mutated?
100+
end
101+
ensure
102+
@graph = old_graph
103+
end
104+
else
105+
case block.arity
106+
when 1 then block.call(self)
107+
else instance_eval(&block)
108+
end
84109
end
85110
end
86111
end

lib/rdf/model/node.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ class Node
1313
include RDF::Resource
1414

1515
##
16-
# Defines the maximum number of interned Node references that can be held
17-
# cached in memory at any one time.
16+
# Cache size may be set through {RDF.config} using `node_cache_size`.
1817
#
1918
# @note caching interned nodes means that two different invocations using the same symbol will result in the same node, which may not be appropriate depending on the graph from which it is used. RDF requires that bnodes with the same label are, in fact, different bnodes, unless they are used within the same document.
20-
CACHE_SIZE = -1 # unlimited by default
21-
22-
##
2319
# @return [RDF::Util::Cache]
2420
# @private
2521
def self.cache
2622
require 'rdf/util/cache' unless defined?(::RDF::Util::Cache)
27-
@cache ||= RDF::Util::Cache.new(CACHE_SIZE)
23+
@cache ||= RDF::Util::Cache.new(RDF.config.node_cache_size)
2824
end
2925

3026
##

0 commit comments

Comments
 (0)