Skip to content

Commit e7b4ff9

Browse files
committed
Finish 2.0.0
2 parents d8ba5f9 + 50290e4 commit e7b4ff9

File tree

5 files changed

+161
-105
lines changed

5 files changed

+161
-105
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 mange 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/json-ld/issues)
10+
* Fork and clone the repo:
11+
`git clone [email protected]:your-username/json-ld.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/json-ld/compare/

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0.beta3
1+
2.0.0

json-ld.gemspec

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,20 @@ Gem::Specification.new do |gem|
2727

2828
gem.required_ruby_version = '>= 2.0'
2929
gem.requirements = []
30-
gem.add_runtime_dependency 'rdf', '>= 2.0.0.beta', '< 3'
30+
gem.add_runtime_dependency 'rdf', '~> 2.0'
3131
gem.add_runtime_dependency 'multi_json', '~> 1.11'
3232
gem.add_development_dependency 'jsonlint', '~> 0.1.0' unless RUBY_ENGINE == "jruby"
3333
gem.add_development_dependency 'oj', '~> 2.12' unless RUBY_ENGINE == "jruby"
3434
gem.add_development_dependency 'yajl-ruby', '~> 1.2' unless RUBY_ENGINE == "jruby"
3535
gem.add_development_dependency "rack-cache", '~> 1.2'
3636
gem.add_development_dependency "rest-client", '~> 1.8'
3737
gem.add_development_dependency "rest-client-components", '~> 1.4'
38-
gem.add_development_dependency 'rdf-isomorphic', '>= 2.0.0.beta', '< 3'
39-
gem.add_development_dependency 'rdf-spec', '>= 2.0.0.beta', '< 3'
40-
gem.add_development_dependency 'rdf-trig', '>= 2.0.0.beta', '< 3'
41-
gem.add_development_dependency 'rdf-turtle', '>= 2.0.0.beta', '< 3'
42-
gem.add_development_dependency 'rdf-vocab', '>= 2.0.0.beta', '< 3'
43-
gem.add_development_dependency 'rdf-xsd', '>= 2.0.0.beta', '< 3'
38+
gem.add_development_dependency 'rdf-isomorphic', '~> 2.0'
39+
gem.add_development_dependency 'rdf-spec', '~> 2.0'
40+
gem.add_development_dependency 'rdf-trig', '~> 2.0'
41+
gem.add_development_dependency 'rdf-turtle', '~> 2.0'
42+
gem.add_development_dependency 'rdf-vocab', '~> 2.0'
43+
gem.add_development_dependency 'rdf-xsd', '~> 2.0'
4444
gem.add_development_dependency 'rspec', '~> 3.4'
4545
gem.add_development_dependency 'rspec-its', '~> 1.0'
4646
gem.add_development_dependency 'yard' , '~> 0.8'

lib/json/ld/format.rb

Lines changed: 109 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -47,123 +47,143 @@ def self.detect(sample)
4747
# @return [Hash{Symbol => Lambda(Array, Hash)}]
4848
def self.cli_commands
4949
{
50-
expand: ->(files, options) do
51-
out = options[:output] || $stdout
52-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
53-
options = options.merge(expandContext: options.delete(:context)) if options.has_key?(:context)
54-
if options[:format] == :jsonld
55-
if files.empty?
56-
# If files are empty, either use options[:execute]
57-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
58-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
59-
JSON::LD::API.expand(input, options) do |expanded|
60-
out.puts expanded.to_json(JSON::LD::JSON_STATE)
50+
expand: {
51+
description: "Expand JSON-LD or parsed RDF",
52+
parse: false,
53+
help: "expand [--context <context-file>] files ...",
54+
lambda: ->(files, options) do
55+
out = options[:output] || $stdout
56+
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
57+
options = options.merge(expandContext: options.delete(:context)) if options.has_key?(:context)
58+
if options[:format] == :jsonld
59+
if files.empty?
60+
# If files are empty, either use options[:execute]
61+
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
62+
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
63+
JSON::LD::API.expand(input, options) do |expanded|
64+
out.puts expanded.to_json(JSON::LD::JSON_STATE)
65+
end
66+
else
67+
files.each do |file|
68+
JSON::LD::API.expand(file, options) do |expanded|
69+
out.puts expanded.to_json(JSON::LD::JSON_STATE)
70+
end
71+
end
6172
end
6273
else
63-
files.each do |file|
64-
JSON::LD::API.expand(file, options) do |expanded|
74+
# Turn RDF into JSON-LD first
75+
RDF::CLI.parse(files, options) do |reader|
76+
JSON::LD::API.fromRdf(reader) do |expanded|
6577
out.puts expanded.to_json(JSON::LD::JSON_STATE)
6678
end
6779
end
6880
end
69-
else
70-
# Turn RDF into JSON-LD first
71-
RDF::CLI.parse(files, options) do |reader|
72-
JSON::LD::API.fromRdf(reader) do |expanded|
73-
out.puts expanded.to_json(JSON::LD::JSON_STATE)
74-
end
75-
end
7681
end
77-
end,
78-
compact: ->(files, options) do
79-
raise ArgumentError, "Compacting requires a context" unless options[:context]
80-
out = options[:output] || $stdout
81-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
82-
if options[:format] == :jsonld
83-
if files.empty?
84-
# If files are empty, either use options[:execute]
85-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
86-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
87-
JSON::LD::API.compact(input, options[:context], options) do |compacted|
88-
out.puts compacted.to_json(JSON::LD::JSON_STATE)
89-
end
90-
else
91-
files.each do |file|
92-
JSON::LD::API.compact(file, options[:context], options) do |compacted|
82+
},
83+
compact: {
84+
description: "Compact JSON-LD or parsed RDF",
85+
parse: false,
86+
help: "compact --context <context-file> files ...",
87+
lambda: ->(files, options) do
88+
raise ArgumentError, "Compacting requires a context" unless options[:context]
89+
out = options[:output] || $stdout
90+
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
91+
if options[:format] == :jsonld
92+
if files.empty?
93+
# If files are empty, either use options[:execute]
94+
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
95+
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
96+
JSON::LD::API.compact(input, options[:context], options) do |compacted|
9397
out.puts compacted.to_json(JSON::LD::JSON_STATE)
9498
end
99+
else
100+
files.each do |file|
101+
JSON::LD::API.compact(file, options[:context], options) do |compacted|
102+
out.puts compacted.to_json(JSON::LD::JSON_STATE)
103+
end
104+
end
95105
end
96-
end
97-
else
98-
# Turn RDF into JSON-LD first
99-
RDF::CLI.parse(files, options) do |reader|
100-
JSON::LD::API.fromRdf(reader) do |expanded|
101-
JSON::LD::API.compact(expanded, options[:context], options) do |compacted|
102-
out.puts compacted.to_json(JSON::LD::JSON_STATE)
106+
else
107+
# Turn RDF into JSON-LD first
108+
RDF::CLI.parse(files, options) do |reader|
109+
JSON::LD::API.fromRdf(reader) do |expanded|
110+
JSON::LD::API.compact(expanded, options[:context], options) do |compacted|
111+
out.puts compacted.to_json(JSON::LD::JSON_STATE)
112+
end
103113
end
104114
end
105115
end
106116
end
107-
end,
108-
flatten: ->(files, options) do
109-
out = options[:output] || $stdout
110-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
111-
if options[:format] == :jsonld
112-
if files.empty?
113-
# If files are empty, either use options[:execute]
114-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
115-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
116-
JSON::LD::API.flatten(input, options[:context], options) do |flattened|
117-
out.puts flattened.to_json(JSON::LD::JSON_STATE)
118-
end
119-
else
120-
files.each do |file|
121-
JSON::LD::API.flatten(file, options[:context], options) do |flattened|
117+
},
118+
flatten: {
119+
description: "Flatten JSON-LD or parsed RDF",
120+
parse: false,
121+
help: "flatten [--context <context-file>] files ...",
122+
lambda: ->(files, options) do
123+
out = options[:output] || $stdout
124+
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
125+
if options[:format] == :jsonld
126+
if files.empty?
127+
# If files are empty, either use options[:execute]
128+
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
129+
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
130+
JSON::LD::API.flatten(input, options[:context], options) do |flattened|
122131
out.puts flattened.to_json(JSON::LD::JSON_STATE)
123132
end
133+
else
134+
files.each do |file|
135+
JSON::LD::API.flatten(file, options[:context], options) do |flattened|
136+
out.puts flattened.to_json(JSON::LD::JSON_STATE)
137+
end
138+
end
124139
end
125-
end
126-
else
127-
# Turn RDF into JSON-LD first
128-
RDF::CLI.parse(files, options) do |reader|
129-
JSON::LD::API.fromRdf(reader) do |expanded|
130-
JSON::LD::API.flatten(expanded, options[:context], options) do |flattened|
131-
out.puts flattened.to_json(JSON::LD::JSON_STATE)
140+
else
141+
# Turn RDF into JSON-LD first
142+
RDF::CLI.parse(files, options) do |reader|
143+
JSON::LD::API.fromRdf(reader) do |expanded|
144+
JSON::LD::API.flatten(expanded, options[:context], options) do |flattened|
145+
out.puts flattened.to_json(JSON::LD::JSON_STATE)
146+
end
132147
end
133148
end
134149
end
135150
end
136-
end,
137-
frame: ->(files, options) do
138-
raise ArgumentError, "Framing requires a frame" unless options[:frame]
139-
out = options[:output] || $stdout
140-
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
141-
if options[:format] == :jsonld
142-
if files.empty?
143-
# If files are empty, either use options[:execute]
144-
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
145-
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
146-
JSON::LD::API.frame(input, options[:frame], options) do |framed|
147-
out.puts framed.to_json(JSON::LD::JSON_STATE)
148-
end
149-
else
150-
files.each do |file|
151-
JSON::LD::API.frame(file, options[:frame], options) do |framed|
151+
},
152+
frame: {
153+
description: "Flatten JSON-LD or parsed RDF",
154+
parse: false,
155+
help: "flatten --frame <frame-file> files ...",
156+
lambda: ->(files, options) do
157+
raise ArgumentError, "Framing requires a frame" unless options[:frame]
158+
out = options[:output] || $stdout
159+
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
160+
if options[:format] == :jsonld
161+
if files.empty?
162+
# If files are empty, either use options[:execute]
163+
input = options[:evaluate] ? StringIO.new(options[:evaluate]) : STDIN
164+
input.set_encoding(options.fetch(:encoding, Encoding::UTF_8))
165+
JSON::LD::API.frame(input, options[:frame], options) do |framed|
152166
out.puts framed.to_json(JSON::LD::JSON_STATE)
153167
end
168+
else
169+
files.each do |file|
170+
JSON::LD::API.frame(file, options[:frame], options) do |framed|
171+
out.puts framed.to_json(JSON::LD::JSON_STATE)
172+
end
173+
end
154174
end
155-
end
156-
else
157-
# Turn RDF into JSON-LD first
158-
RDF::CLI.parse(files, options) do |reader|
159-
JSON::LD::API.fromRdf(reader) do |expanded|
160-
JSON::LD::API.frame(expanded, options[:frame], options) do |framed|
161-
out.puts framed.to_json(JSON::LD::JSON_STATE)
175+
else
176+
# Turn RDF into JSON-LD first
177+
RDF::CLI.parse(files, options) do |reader|
178+
JSON::LD::API.fromRdf(reader) do |expanded|
179+
JSON::LD::API.frame(expanded, options[:frame], options) do |framed|
180+
out.puts framed.to_json(JSON::LD::JSON_STATE)
181+
end
162182
end
163183
end
164184
end
165185
end
166-
end,
186+
},
167187
}
168188
end
169189

spec/format_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,37 +75,37 @@
7575

7676
describe "#expand" do
7777
it "expands RDF" do
78-
expect {RDF::CLI.exec_command("expand", [ttl], format: :ttl)}.to write.to(:output)
78+
expect {RDF::CLI.exec(["expand", ttl], format: :ttl)}.to write.to(:output)
7979
end
8080
it "expands JSON" do
81-
expect {RDF::CLI.exec_command("expand", [json], format: :jsonld)}.to write.to(:output)
81+
expect {RDF::CLI.exec(["expand", json], format: :jsonld)}.to write.to(:output)
8282
end
8383
end
8484

8585
describe "#compact" do
8686
it "compacts RDF" do
87-
expect {RDF::CLI.exec_command("compact", [ttl], context: context, format: :ttl)}.to write.to(:output)
87+
expect {RDF::CLI.exec(["compact", ttl], context: context, format: :ttl)}.to write.to(:output)
8888
end
8989
it "compacts JSON" do
90-
expect {RDF::CLI.exec_command("compact", [json], context: context, format: :jsonld)}.to write.to(:output)
90+
expect {RDF::CLI.exec(["compact", json], context: context, format: :jsonld)}.to write.to(:output)
9191
end
9292
end
9393

9494
describe "#flatten" do
9595
it "flattens RDF" do
96-
expect {RDF::CLI.exec_command("flatten", [ttl], context: context, format: :ttl)}.to write.to(:output)
96+
expect {RDF::CLI.exec(["flatten", ttl], context: context, format: :ttl)}.to write.to(:output)
9797
end
9898
it "flattens JSON" do
99-
expect {RDF::CLI.exec_command("flatten", [json], context: context, format: :jsonld)}.to write.to(:output)
99+
expect {RDF::CLI.exec(["flatten", json], context: context, format: :jsonld)}.to write.to(:output)
100100
end
101101
end
102102

103103
describe "#frame" do
104104
it "frames RDF" do
105-
expect {RDF::CLI.exec_command("frame", [ttl], frame: context, format: :ttl)}.to write.to(:output)
105+
expect {RDF::CLI.exec(["frame", ttl], frame: context, format: :ttl)}.to write.to(:output)
106106
end
107107
it "frames JSON" do
108-
expect {RDF::CLI.exec_command("frame", [json], frame: context, format: :jsonld)}.to write.to(:output)
108+
expect {RDF::CLI.exec(["frame", json], frame: context, format: :jsonld)}.to write.to(:output)
109109
end
110110
end
111111
end

0 commit comments

Comments
 (0)