Skip to content

Commit

Permalink
Finish 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Apr 11, 2016
2 parents d8ba5f9 + 50290e4 commit e7b4ff9
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 105 deletions.
36 changes: 36 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,36 @@
# How to contribute

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.

## Development

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.

* create or respond to an issue on the [Github Repository](http://github.com/ruby-rdf/json-ld/issues)
* Fork and clone the repo:
`git clone git@github.com:your-username/json-ld.git`
* Install bundle:
`bundle install`
* Create tests in RSpec and make sure you achieve at least 90% code coverage for the feature your adding or behavior being modified.
* Push to your fork and [submit a pull request][pr].

## Do's and Dont's
* Do your best to adhere to the existing coding conventions and idioms.
* Don't use hard tabs, and don't leave trailing whitespace on any line.
Before committing, run `git diff --check` to make sure of this.
* Do document every method you add using [YARD][] annotations. Read the
[tutorial][YARD-GS] or just look at the existing code for examples.
* Don't touch the `.gemspec` or `VERSION` files. If you need to change them,
do so on your private branch only.
* Do feel free to add yourself to the `CREDITS` file and the
corresponding list in the the `README`. Alphabetical order applies.
* Don't touch the `AUTHORS` file. If your contributions are significant
enough, be assured we will eventually add you in there.
* Do note that in order for us to merge any non-trivial changes (as a rule
of thumb, additions larger than about 15 lines of code), we need an
explicit [public domain dedication][PDD] on record from you.

[YARD]: http://yardoc.org/
[YARD-GS]: http://rubydoc.info/docs/yard/file/docs/GettingStarted.md
[PDD]: http://lists.w3.org/Archives/Public/public-rdf-ruby/2010May/0013.html
[pr]: https://github.com/ruby-rdf/json-ld/compare/
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
2.0.0.beta3
2.0.0
14 changes: 7 additions & 7 deletions json-ld.gemspec
Expand Up @@ -27,20 +27,20 @@ Gem::Specification.new do |gem|

gem.required_ruby_version = '>= 2.0'
gem.requirements = []
gem.add_runtime_dependency 'rdf', '>= 2.0.0.beta', '< 3'
gem.add_runtime_dependency 'rdf', '~> 2.0'
gem.add_runtime_dependency 'multi_json', '~> 1.11'
gem.add_development_dependency 'jsonlint', '~> 0.1.0' unless RUBY_ENGINE == "jruby"
gem.add_development_dependency 'oj', '~> 2.12' unless RUBY_ENGINE == "jruby"
gem.add_development_dependency 'yajl-ruby', '~> 1.2' unless RUBY_ENGINE == "jruby"
gem.add_development_dependency "rack-cache", '~> 1.2'
gem.add_development_dependency "rest-client", '~> 1.8'
gem.add_development_dependency "rest-client-components", '~> 1.4'
gem.add_development_dependency 'rdf-isomorphic', '>= 2.0.0.beta', '< 3'
gem.add_development_dependency 'rdf-spec', '>= 2.0.0.beta', '< 3'
gem.add_development_dependency 'rdf-trig', '>= 2.0.0.beta', '< 3'
gem.add_development_dependency 'rdf-turtle', '>= 2.0.0.beta', '< 3'
gem.add_development_dependency 'rdf-vocab', '>= 2.0.0.beta', '< 3'
gem.add_development_dependency 'rdf-xsd', '>= 2.0.0.beta', '< 3'
gem.add_development_dependency 'rdf-isomorphic', '~> 2.0'
gem.add_development_dependency 'rdf-spec', '~> 2.0'
gem.add_development_dependency 'rdf-trig', '~> 2.0'
gem.add_development_dependency 'rdf-turtle', '~> 2.0'
gem.add_development_dependency 'rdf-vocab', '~> 2.0'
gem.add_development_dependency 'rdf-xsd', '~> 2.0'
gem.add_development_dependency 'rspec', '~> 3.4'
gem.add_development_dependency 'rspec-its', '~> 1.0'
gem.add_development_dependency 'yard' , '~> 0.8'
Expand Down
198 changes: 109 additions & 89 deletions lib/json/ld/format.rb
Expand Up @@ -47,123 +47,143 @@ def self.detect(sample)
# @return [Hash{Symbol => Lambda(Array, Hash)}]
def self.cli_commands
{
expand: ->(files, options) do
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
options = options.merge(expandContext: options.delete(:context)) if options.has_key?(:context)
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.expand(input, options) do |expanded|
out.puts expanded.to_json(JSON::LD::JSON_STATE)
expand: {
description: "Expand JSON-LD or parsed RDF",
parse: false,
help: "expand [--context <context-file>] files ...",
lambda: ->(files, options) do
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
options = options.merge(expandContext: options.delete(:context)) if options.has_key?(:context)
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.expand(input, options) do |expanded|
out.puts expanded.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.expand(file, options) do |expanded|
out.puts expanded.to_json(JSON::LD::JSON_STATE)
end
end
end
else
files.each do |file|
JSON::LD::API.expand(file, options) do |expanded|
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
out.puts expanded.to_json(JSON::LD::JSON_STATE)
end
end
end
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
out.puts expanded.to_json(JSON::LD::JSON_STATE)
end
end
end
end,
compact: ->(files, options) do
raise ArgumentError, "Compacting requires a context" unless options[:context]
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.compact(input, options[:context], options) do |compacted|
out.puts compacted.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.compact(file, options[:context], options) do |compacted|
},
compact: {
description: "Compact JSON-LD or parsed RDF",
parse: false,
help: "compact --context <context-file> files ...",
lambda: ->(files, options) do
raise ArgumentError, "Compacting requires a context" unless options[:context]
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.compact(input, options[:context], options) do |compacted|
out.puts compacted.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.compact(file, options[:context], options) do |compacted|
out.puts compacted.to_json(JSON::LD::JSON_STATE)
end
end
end
end
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
JSON::LD::API.compact(expanded, options[:context], options) do |compacted|
out.puts compacted.to_json(JSON::LD::JSON_STATE)
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
JSON::LD::API.compact(expanded, options[:context], options) do |compacted|
out.puts compacted.to_json(JSON::LD::JSON_STATE)
end
end
end
end
end
end,
flatten: ->(files, options) do
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.flatten(input, options[:context], options) do |flattened|
out.puts flattened.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.flatten(file, options[:context], options) do |flattened|
},
flatten: {
description: "Flatten JSON-LD or parsed RDF",
parse: false,
help: "flatten [--context <context-file>] files ...",
lambda: ->(files, options) do
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.flatten(input, options[:context], options) do |flattened|
out.puts flattened.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.flatten(file, options[:context], options) do |flattened|
out.puts flattened.to_json(JSON::LD::JSON_STATE)
end
end
end
end
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
JSON::LD::API.flatten(expanded, options[:context], options) do |flattened|
out.puts flattened.to_json(JSON::LD::JSON_STATE)
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
JSON::LD::API.flatten(expanded, options[:context], options) do |flattened|
out.puts flattened.to_json(JSON::LD::JSON_STATE)
end
end
end
end
end
end,
frame: ->(files, options) do
raise ArgumentError, "Framing requires a frame" unless options[:frame]
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.frame(input, options[:frame], options) do |framed|
out.puts framed.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.frame(file, options[:frame], options) do |framed|
},
frame: {
description: "Flatten JSON-LD or parsed RDF",
parse: false,
help: "flatten --frame <frame-file> files ...",
lambda: ->(files, options) do
raise ArgumentError, "Framing requires a frame" unless options[:frame]
out = options[:output] || $stdout
out.set_encoding(Encoding::UTF_8) if RUBY_PLATFORM == "java"
if options[:format] == :jsonld
if files.empty?
# 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))
JSON::LD::API.frame(input, options[:frame], options) do |framed|
out.puts framed.to_json(JSON::LD::JSON_STATE)
end
else
files.each do |file|
JSON::LD::API.frame(file, options[:frame], options) do |framed|
out.puts framed.to_json(JSON::LD::JSON_STATE)
end
end
end
end
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
JSON::LD::API.frame(expanded, options[:frame], options) do |framed|
out.puts framed.to_json(JSON::LD::JSON_STATE)
else
# Turn RDF into JSON-LD first
RDF::CLI.parse(files, options) do |reader|
JSON::LD::API.fromRdf(reader) do |expanded|
JSON::LD::API.frame(expanded, options[:frame], options) do |framed|
out.puts framed.to_json(JSON::LD::JSON_STATE)
end
end
end
end
end
end,
},
}
end

Expand Down
16 changes: 8 additions & 8 deletions spec/format_spec.rb
Expand Up @@ -75,37 +75,37 @@

describe "#expand" do
it "expands RDF" do
expect {RDF::CLI.exec_command("expand", [ttl], format: :ttl)}.to write.to(:output)
expect {RDF::CLI.exec(["expand", ttl], format: :ttl)}.to write.to(:output)
end
it "expands JSON" do
expect {RDF::CLI.exec_command("expand", [json], format: :jsonld)}.to write.to(:output)
expect {RDF::CLI.exec(["expand", json], format: :jsonld)}.to write.to(:output)
end
end

describe "#compact" do
it "compacts RDF" do
expect {RDF::CLI.exec_command("compact", [ttl], context: context, format: :ttl)}.to write.to(:output)
expect {RDF::CLI.exec(["compact", ttl], context: context, format: :ttl)}.to write.to(:output)
end
it "compacts JSON" do
expect {RDF::CLI.exec_command("compact", [json], context: context, format: :jsonld)}.to write.to(:output)
expect {RDF::CLI.exec(["compact", json], context: context, format: :jsonld)}.to write.to(:output)
end
end

describe "#flatten" do
it "flattens RDF" do
expect {RDF::CLI.exec_command("flatten", [ttl], context: context, format: :ttl)}.to write.to(:output)
expect {RDF::CLI.exec(["flatten", ttl], context: context, format: :ttl)}.to write.to(:output)
end
it "flattens JSON" do
expect {RDF::CLI.exec_command("flatten", [json], context: context, format: :jsonld)}.to write.to(:output)
expect {RDF::CLI.exec(["flatten", json], context: context, format: :jsonld)}.to write.to(:output)
end
end

describe "#frame" do
it "frames RDF" do
expect {RDF::CLI.exec_command("frame", [ttl], frame: context, format: :ttl)}.to write.to(:output)
expect {RDF::CLI.exec(["frame", ttl], frame: context, format: :ttl)}.to write.to(:output)
end
it "frames JSON" do
expect {RDF::CLI.exec_command("frame", [json], frame: context, format: :jsonld)}.to write.to(:output)
expect {RDF::CLI.exec(["frame", json], frame: context, format: :jsonld)}.to write.to(:output)
end
end
end
Expand Down

0 comments on commit e7b4ff9

Please sign in to comment.