Skip to content

Commit 2a0ce29

Browse files
committed
Finish 0.3.2
2 parents 1b78929 + ee54c41 commit 2a0ce29

7 files changed

Lines changed: 54 additions & 24 deletions

File tree

.travis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ script: "bundle exec rspec spec"
44
env:
55
- CI=true
66
rvm:
7-
- 2.2.6
8-
- 2.3.3
9-
- 2.4.0
10-
- jruby
11-
- rbx
7+
- 2.2
8+
- 2.3
9+
- 2.4
10+
- jruby-9
11+
- rbx-3
1212
cache: bundler
1313
sudo: false
1414
matrix:
1515
allow_failures:
16-
- rvm: rbx
17-
- rvm: jruby
16+
- rvm: jruby-9
17+
- rvm: rbx-3
18+
dist: trusty

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ Full documentation available on [Rubydoc.info][LD-Patch doc]
5353
operator = LD::Patch.parse(patch, base_uri: "http://rubygems.org/gems/ld-patch")
5454
operator.execute(queryable) # alternatively queryable.query(operator)
5555

56+
## Command Line
57+
When the `linkeddata` gem is installed, RDF.rb includes a `rdf` executable which acts as a wrapper to perform a number of different
58+
operations on RDF files, including LD::Patch, which is used as a stream command and must be followed by serialize to see the results. The commands specific to LD::Patch is
59+
60+
* `ld-patch`: Patch the current graph using a patch file
61+
62+
Using this command requires either a `patch-input` where the patch is URI encoded, or `patch-file`, which references a URI or file path to the patch.
63+
Example usage:
64+
65+
rdf patch serialize https://raw.githubusercontent.com/ruby-rdf/ld-patch/develop/etc/doap.ttl \
66+
--patch-input Add%20%7B%20%3Chttp://example.org/s2%3E%20%3Chttp://example.org/p2%3E%20%3Chttp://example.org/o2%3E%20%7D%20. \
67+
--output-format ttl
68+
5669
## Implementation Notes
5770
The reader uses the [EBNF][] gem to generate first, follow and branch tables, and uses the `Parser` and `Lexer` modules to implement the LD Patch parser.
5871

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.1
1+
0.3.2

bin/ldpatch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def run(graph, options = {})
2222

2323
patch = LD::Patch.parse(options[:patch], options)
2424

25-
puts ("\nSSE:\n" + patch.to_sse) if options[:debug] || options[:to_sse]
25+
puts ("\nSXP:\n" + patch.to_sse) if options[:debug] || options[:to_sxp]
2626

27-
unless options[:to_sse]
27+
unless options[:to_sxp]
2828
res = patch.execute(graph, options)
2929
puts res.dump(:ttl, base_uri: patch.base_uri, prefixes: patch.prefixes, standard_prefixes: true)
3030
end
@@ -35,7 +35,7 @@ opts = GetoptLong.new(
3535
["--execute", "-e", GetoptLong::REQUIRED_ARGUMENT],
3636
["--patch", GetoptLong::REQUIRED_ARGUMENT],
3737
["--progress", GetoptLong::NO_ARGUMENT],
38-
["--to-sse", GetoptLong::NO_ARGUMENT],
38+
["--to-sxp", GetoptLong::NO_ARGUMENT],
3939
["--validate", GetoptLong::NO_ARGUMENT],
4040
["--verbose", GetoptLong::NO_ARGUMENT],
4141
["--help", "-?", GetoptLong::NO_ARGUMENT]
@@ -50,7 +50,7 @@ opts.each do |opt, arg|
5050
when '--execute' then options[:patch] = arg
5151
when '--patch' then options[:patch] = RDF::Util::File.open_file(arg).read
5252
when '--progress' then options[:debug] ||= 2
53-
when '--to-sse' then options[:to_sse] = true
53+
when '--to-sxp' then options[:to_sxp] = true
5454
when '--validate' then options[:validate] = true
5555
when '--verbose' then options[:verbose] = true
5656
when "--help"
@@ -61,7 +61,7 @@ opts.each do |opt, arg|
6161
puts " --execute,-e: Use option argument as the patch input"
6262
puts " --patch: Location of patch document"
6363
puts " --progress Display parse tree"
64-
puts " --to-sse: Generate SSE for patch instead of running query"
64+
puts " --to-sxp: Generate S-Expression for patch instead of running query"
6565
puts " --validate: Validate patch document"
6666
puts " --verbose: Display details of processing"
6767
puts " --help,-?: This message"

ld-patch.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Gem::Specification.new do |gem|
99
gem.homepage = "http://github.com/ruby-rdf/ld-patch"
1010
gem.license = 'Unlicense'
1111
gem.summary = "W3C Linked Data Patch Format for RDF.rb."
12-
gem.rubyforge_project = 'ld-patch'
1312

1413
gem.authors = ['Gregg Kellogg']
1514
gem.email = 'public-rdf-ruby@w3.org'

lib/ld/patch/format.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,43 @@ class Format < RDF::Format
2020
def self.cli_commands
2121
{
2222
patch: {
23-
description: "Patch the current graph using a URI Encoded patch file, or a referenced path file/URI",
24-
help: "patch [--patch 'patch'] [--patch-file file]",
23+
description: "Patch the current graph using a patch file",
24+
help: "patch [--patch-input 'patch'] [--patch-file file]",
25+
control: :button,
2526
parse: true,
2627
lambda: -> (argv, opts) do
27-
opts[:patch] ||= RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
28-
raise ArgumentError, "Patching requires a URI encoded patch or reference to patch resource" unless opts[:patch]
29-
$stdout.puts "Patch"
30-
patch = LD::Patch.parse(opts[:patch], base_uri: opts.fetch(:patch_file, "http://rubygems.org/gems/ld-patch"))
28+
opts[:patch_input] ||= case opts[:patch_file]
29+
when IO, StringIO then opts[:patch_file]
30+
else RDF::Util::File.open_file(opts[:patch_file]) {|f| f.read}
31+
end
32+
raise ArgumentError, "Patching requires a patch or reference to patch resource" unless opts[:patch_input]
33+
opts[:logger].info "Patch"
34+
patch = LD::Patch.parse(opts[:patch_input], base_uri: opts.fetch(:patch_file, "http://rubygems.org/gems/ld-patch"))
35+
opts[:messages][:"S-Expression"] = [patch.to_sse] if opts[:to_sxp]
3136
RDF::CLI.repository.query(patch)
3237
end,
3338
options: [
3439
RDF::CLI::Option.new(
35-
symbol: :patch,
40+
symbol: :patch_input,
3641
datatype: String,
37-
on: ["--patch STRING"],
42+
control: :none,
43+
on: ["--patch-input STRING"],
3844
description: "Patch in URI encoded format"
3945
) {|v| URI.decode(v)},
4046
RDF::CLI::Option.new(
4147
symbol: :patch_file,
4248
datatype: String,
49+
control: :url2,
4350
on: ["--patch-file URI"],
44-
description: "URI of patch file"
51+
description: "Patch file"
4552
) {|v| RDF::URI(v)},
53+
RDF::CLI::Option.new(
54+
symbol: :to_sxp,
55+
datatype: String,
56+
control: :checkbox,
57+
on: ["--to-sxp"],
58+
description: "Instead of patching repository, display parsed patch as an S-Expression"
59+
),
4660
]
4761
}
4862
}

spec/format_spec.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
it "patches from file" do
3737
expect {RDF::CLI.exec(["patch", "serialize", nt], patch_file: patch)}.to write.to(:output)
3838
end
39+
it "patches from StringIO" do
40+
expect {RDF::CLI.exec(["patch", "serialize", nt], patch_file: StringIO.new(File.read(patch)))}.to write.to(:output)
41+
end
3942
it "patches from argument" do
40-
expect {RDF::CLI.exec(["patch", "serialize", nt], patch: patch_enc)}.to write.to(:output)
43+
expect {RDF::CLI.exec(["patch", "serialize", nt], patch_input: patch_enc)}.to write.to(:output)
4144
end
4245
end
4346
end

0 commit comments

Comments
 (0)