Skip to content

Commit 7b9a4c0

Browse files
committed
Finish 0.3.0.beta2
2 parents f1bf683 + dbd8815 commit 7b9a4c0

File tree

7 files changed

+137
-1
lines changed

7 files changed

+137
-1
lines changed

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# How to contribute
2+
3+
Community contributions are essential for keeping Ruby RDF great. We want to keep it as easy as possible to contribute changes that get things working in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things.
4+
5+
## Development
6+
7+
This repository uses [Git Flow](https://github.com/nvie/gitflow) to manage development and release activity. All submissions _must_ be on a feature branch based on the _develop_ branch to ease staging and integration.
8+
9+
* create or respond to an issue on the [Github Repository](http://github.com/ruby-rdf/ld-patch/issues)
10+
* Fork and clone the repo:
11+
`git clone [email protected]:your-username/ld-patch.git`
12+
* Install bundle:
13+
`bundle install`
14+
* Create tests in RSpec and make sure you achieve at least 90% code coverage for the feature your adding or behavior being modified.
15+
* Push to your fork and [submit a pull request][pr].
16+
17+
## Do's and Dont's
18+
* Do your best to adhere to the existing coding conventions and idioms.
19+
* Don't use hard tabs, and don't leave trailing whitespace on any line.
20+
Before committing, run `git diff --check` to make sure of this.
21+
* Do document every method you add using [YARD][] annotations. Read the
22+
[tutorial][YARD-GS] or just look at the existing code for examples.
23+
* Don't touch the `.gemspec` or `VERSION` files. If you need to change them,
24+
do so on your private branch only.
25+
* Do feel free to add yourself to the `CREDITS` file and the
26+
corresponding list in the the `README`. Alphabetical order applies.
27+
* Don't touch the `AUTHORS` file. If your contributions are significant
28+
enough, be assured we will eventually add you in there.
29+
* Do note that in order for us to merge any non-trivial changes (as a rule
30+
of thumb, additions larger than about 15 lines of code), we need an
31+
explicit [public domain dedication][PDD] on record from you.
32+
33+
[YARD]: http://yardoc.org/
34+
[YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
35+
[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
36+
[pr]: https://github.com/ruby-rdf/ld-patch/compare/

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.3.0.beta1
1+
0.3.0.beta2

lib/ld/patch.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module LD
99
#
1010
# @author [Gregg Kellogg](http://greggkellogg.net/)
1111
module Patch
12+
require 'ld/patch/format'
1213
autoload :Algebra, 'ld/patch/algebra'
1314
autoload :Meta, 'ld/patch/meta'
1415
autoload :Parser, 'ld/patch/parser'

lib/ld/patch/format.rb

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module LD::Patch
2+
##
3+
# LD::Patch format specification. Note that this format does not define any readers or writers.
4+
#
5+
# @example Obtaining an LD Patch format class
6+
# RDF::Format.for(:ldp) #=> LD::Patch::Format
7+
# RDF::Format.for("etc/foaf.ldp")
8+
# RDF::Format.for(:file_name => "etc/foaf.ldp")
9+
# RDF::Format.for(file_extension: "ldp")
10+
# RDF::Format.for(:content_type => "text/ldpatch")
11+
#
12+
# @see http://www.w3.org/TR/ldpatch/
13+
class Format < RDF::Format
14+
content_type 'text/ldpatch', extension: :ldp
15+
content_encoding 'utf-8'
16+
17+
##
18+
# Hash of CLI commands appropriate for this format
19+
# @return [Hash{Symbol => Lambda(Array, Hash)}]
20+
def self.cli_commands
21+
{
22+
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]",
25+
parse: true,
26+
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"))
31+
RDF::CLI.repository.query(patch)
32+
end,
33+
options: [
34+
RDF::CLI::Option.new(
35+
symbol: :patch,
36+
datatype: String,
37+
on: ["--patch STRING"],
38+
description: "Patch in URI encoded format"
39+
) {|v| URI.decode(v)},
40+
RDF::CLI::Option.new(
41+
symbol: :patch_file,
42+
datatype: String,
43+
on: ["--patch-file URI"],
44+
description: "URI of patch file"
45+
) {|v| RDF::URI(v)},
46+
]
47+
}
48+
}
49+
end
50+
51+
def self.to_sym; :ldpatch; end
52+
end
53+
end

spec/format_spec.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# coding: utf-8
2+
$:.unshift "."
3+
require 'spec_helper'
4+
require 'rdf/spec/format'
5+
6+
describe LD::Patch::Format do
7+
it_behaves_like 'an RDF::Format' do
8+
let(:format_class) {JSON::LD::Format}
9+
end
10+
11+
describe ".for" do
12+
formats = [
13+
:ldpatch,
14+
"etc/doap.ldp",
15+
{file_name: 'etc/doap.ldp'},
16+
{file_extension: 'ldp'},
17+
{content_type: 'text/ldpatch'},
18+
].each do |arg|
19+
it "discovers with #{arg.inspect}" do
20+
expect(RDF::Format.for(arg)).to eq described_class
21+
end
22+
end
23+
end
24+
25+
describe "#to_sym" do
26+
specify {expect(described_class.to_sym).to eq :ldpatch}
27+
end
28+
29+
describe ".cli_commands" do
30+
require 'rdf/cli'
31+
let(:nt) {File.expand_path("../test-files/1triple.nt", __FILE__)}
32+
let(:patch) {File.expand_path("../test-files/add-1triple.ldpatch", __FILE__)}
33+
let(:patch_enc) {File.read(patch)} # Not encoded, since decode done in option parsing
34+
35+
describe "#patch" do
36+
it "patches from file" do
37+
expect {RDF::CLI.exec(["patch", "serialize", nt], patch_file: patch)}.to write.to(:output)
38+
end
39+
it "patches from argument" do
40+
expect {RDF::CLI.exec(["patch", "serialize", nt], patch: patch_enc)}.to write.to(:output)
41+
end
42+
end
43+
end
44+
end

spec/test-files/1triple.nt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<http://example.org/s1> <http://example.org/p1> <http://example.org/o1> .

spec/test-files/add-1triple.ldpatch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add { <http://example.org/s2> <http://example.org/p2> <http://example.org/o2> } .

0 commit comments

Comments
 (0)