-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support schemas via lib/linked_data_fragments
This is the first step in a refactoring to move schemas to lib. Adds tests for the schemas.
- Loading branch information
Tom Johnson
committed
Feb 2, 2017
1 parent
52c72c5
commit 8fbe5a0
Showing
12 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'active_triples' | ||
|
||
# must require 'rdf/vocab' first, due to const_missing metaprogramming in | ||
# pre-2.0 verisons | ||
require 'rdf/vocab' | ||
require 'rdf/vocab/hydra' | ||
require 'rdf/vocab/void' | ||
|
||
require 'linked_data_fragments/schemas' | ||
|
||
## | ||
# A linked data caching fragment | ||
module LinkedDataFragments | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'linked_data_fragments/schemas/control_schema' | ||
require 'linked_data_fragments/schemas/dataset_schema' | ||
require 'linked_data_fragments/schemas/result_schema' | ||
require 'linked_data_fragments/schemas/template_schema' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module LinkedDataFragments | ||
## | ||
# A HydraCore control schema | ||
class ControlSchema < ActiveTriples::Schema | ||
property :variable, :predicate => RDF::Vocab::HYDRA.variable | ||
property :property, :predicate => RDF::Vocab::HYDRA.property, :cast => false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module LinkedDataFragments | ||
## | ||
# A schema for `hydracore:Collection`/`Dataset` nodes. | ||
class DatasetSchema < ActiveTriples::Schema | ||
property :subset, predicate: RDF::VOID.subset | ||
property :uri_lookup_endpoint, predicate: RDF::VOID.uriLookupEndpoint | ||
|
||
# Change search so that it points to a search node. | ||
property :search, predicate: RDF::URI.intern("http://www.w3.org/ns/hydra/core#search") | ||
property :member, predicate: RDF::URI.intern("http://www.w3.org/ns/hydra/core#member") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module LinkedDataFragments | ||
## | ||
# Schema for Result model | ||
class ResultSchema < ActiveTriples::Schema | ||
property :subset, :predicate => RDF::VOID.subset | ||
|
||
# Descriptive | ||
property :title, :predicate => RDF::Vocab::DC.title | ||
property :description, :predicate => RDF::Vocab::DC.description | ||
property :source, :predicate => RDF::Vocab::DC.source | ||
|
||
# Pagination | ||
property :triples_count, :predicate => RDF::Vocab::VOID.triples | ||
property :total_items, :predicate => RDF::URI("http://www.w3.org/ns/hydra/core#totalItems") | ||
property :items_per_page, :predicate => RDF::URI("http://www.w3.org/ns/hydra/core#itemsPerPage") | ||
property :first_page, :predicate => RDF::URI("http://www.w3.org/ns/hydra/core#firstPage") | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module LinkedDataFragments | ||
## | ||
# Schema for template models | ||
class TemplateSchema < ActiveTriples::Schema | ||
property :template, :predicate => RDF::Vocab::HYDRA.search | ||
property :mapping, :predicate => RDF::Vocab::HYDRA.mapping | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe LinkedDataFragments::ControlSchema do | ||
it_behaves_like 'a schema', [:variable, :property] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe LinkedDataFragments::DatasetSchema do | ||
it_behaves_like 'a schema', [:subset, :uri_lookup_endpoint, :search, :member] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'spec_helper' | ||
|
||
describe LinkedDataFragments::ResultSchema do | ||
it_behaves_like 'a schema', [:subset, | ||
:title, | ||
:description, | ||
:source, | ||
:triples_count, | ||
:total_items, | ||
:items_per_page, | ||
:first_page | ||
] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require 'spec_helper' | ||
|
||
describe LinkedDataFragments::TemplateSchema do | ||
it_behaves_like 'a schema', [:template, :mapping] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'vcr_setup' | ||
require 'linked_data_fragments' | ||
|
||
Dir['./spec/support/**/*.rb'].each { |f| require f } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
shared_examples 'a schema' do |properties| | ||
let(:fake_source) do | ||
klass = Class.new { include ActiveTriples::RDFSource } | ||
klass.apply_schema described_class | ||
klass | ||
end | ||
|
||
let(:source) { fake_source.new } | ||
let(:value) { :moomin } | ||
|
||
properties.each do |property| | ||
it "has configured property #{property}" do | ||
expect { source.send("#{property}=".to_sym, value) } | ||
.to change { source.send(property).to_a } | ||
.to contain_exactly(value) | ||
end | ||
end | ||
end |