active-triples 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGES.md +6 -0
- data/lib/active_triples.rb +3 -0
- data/lib/active_triples/extension_strategy.rb +16 -0
- data/lib/active_triples/property.rb +13 -0
- data/lib/active_triples/rdf_source.rb +12 -0
- data/lib/active_triples/schema.rb +20 -0
- data/lib/active_triples/version.rb +1 -1
- data/spec/active_triples/extension_strategy_spec.rb +27 -0
- data/spec/active_triples/property_spec.rb +29 -0
- data/spec/active_triples/rdf_source_spec.rb +19 -1
- data/spec/active_triples/schema_spec.rb +15 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8509c08a01f7e74117e8ea5791aaf2728360c80
|
4
|
+
data.tar.gz: f1941f479ed0e56364c957497e8d8f39403b6efa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faff9891e25d5962d178cf88baceaaaf0b40b8f0d0bca6538d15421834f6529d00cdbe5e5995e1cfef868a8f593a1a2e84aa3309b3cb933ee7e5192333fcfc4c
|
7
|
+
data.tar.gz: 76ef886b46c6cafb1f24a64df413a7d2f8d08aff2e97e2821cbca91e827bd03089eb337ace703aacf774d774b764c5320de891dd88320468608c408c079b214f
|
data/.travis.yml
CHANGED
data/CHANGES.md
CHANGED
data/lib/active_triples.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveTriples
|
2
|
+
##
|
3
|
+
# Default property applying strategy which just copies all configured properties
|
4
|
+
# from a data property to a new resource, assuming it supports the #property
|
5
|
+
# interface.
|
6
|
+
class ExtensionStrategy
|
7
|
+
class << self
|
8
|
+
# @param [ActiveTriples::Resource, #property] resource A resource to copy
|
9
|
+
# the property to.
|
10
|
+
# @param [ActiveTriples::Property] property The property to copy.
|
11
|
+
def apply(resource, property)
|
12
|
+
resource.property property.name, property.to_h
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveTriples
|
2
|
+
##
|
3
|
+
# A value object to encapsulate what a Property is. Instantiate with a hash of
|
4
|
+
# options.
|
5
|
+
class Property < OpenStruct
|
6
|
+
# Returns the property's configuration values. Will not return #name, which is
|
7
|
+
# meant to only be accessible via the accessor.
|
8
|
+
# @return [Hash] Configuration values for this property.
|
9
|
+
def to_h
|
10
|
+
super.except(:name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -546,6 +546,18 @@ module ActiveTriples
|
|
546
546
|
new(uri, vals)
|
547
547
|
end
|
548
548
|
|
549
|
+
##
|
550
|
+
# Apply a predicate mapping using a given strategy.
|
551
|
+
#
|
552
|
+
# @param [ActiveTriples::Schema, #properties] schema A schema to apply.
|
553
|
+
# @param [#apply!] strategy A strategy for applying. Defaults
|
554
|
+
# to ActiveTriples::ExtensionStrategy
|
555
|
+
def apply_schema(schema, strategy=ActiveTriples::ExtensionStrategy)
|
556
|
+
schema.properties.each do |property|
|
557
|
+
strategy.apply(self, property)
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
549
561
|
##
|
550
562
|
# Test if the rdf_subject that would be generated using a
|
551
563
|
# specific ID is already in use in the triplestore.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module ActiveTriples
|
2
|
+
##
|
3
|
+
# Super class which provides a simple property DSL for defining property ->
|
4
|
+
# predicate mappings.
|
5
|
+
class Schema
|
6
|
+
class << self
|
7
|
+
# @param [Symbol] property The property name on the object.
|
8
|
+
# @param [Hash] options Options for the property.
|
9
|
+
# @option options [RDF::URI] :predicate The predicate to map the property
|
10
|
+
# to.
|
11
|
+
def property(property, options)
|
12
|
+
properties << Property.new(options.merge(:name => property))
|
13
|
+
end
|
14
|
+
|
15
|
+
def properties
|
16
|
+
@properties ||= []
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActiveTriples::ExtensionStrategy do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
describe ".apply" do
|
7
|
+
it "should copy the property to the asset" do
|
8
|
+
asset = build_asset
|
9
|
+
property = build_property("name", {:predicate => RDF::DC.title})
|
10
|
+
|
11
|
+
subject.apply(asset, property)
|
12
|
+
|
13
|
+
expect(asset).to have_received(:property).with(property.name, property.to_h)
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_asset
|
17
|
+
object_double(ActiveTriples::Resource, :property => nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_property(name, options)
|
21
|
+
property = object_double(ActiveTriples::Property.new(:name => nil))
|
22
|
+
allow(property).to receive(:name).and_return(name)
|
23
|
+
allow(property).to receive(:to_h).and_return(options)
|
24
|
+
property
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActiveTriples::Property do
|
4
|
+
subject { described_class.new(options) }
|
5
|
+
let(:options) do
|
6
|
+
{
|
7
|
+
:name => :title,
|
8
|
+
:predicate => RDF::DC.title,
|
9
|
+
:class_name => "Test"
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create accessors for each passed option" do
|
14
|
+
expect(subject.name).to eq :title
|
15
|
+
expect(subject.predicate).to eq RDF::DC.title
|
16
|
+
expect(subject.class_name).to eq "Test"
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#to_h" do
|
20
|
+
it "should not return the property's name" do
|
21
|
+
expect(subject.to_h).to eq (
|
22
|
+
{
|
23
|
+
:predicate => RDF::DC.title,
|
24
|
+
:class_name => "Test"
|
25
|
+
}
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,5 +1,23 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ActiveTriples::RDFSource do
|
4
|
-
let(:dummy_source) { Class.new { include
|
4
|
+
let(:dummy_source) { Class.new { include ActiveTriples::RDFSource } }
|
5
|
+
|
6
|
+
subject { source_class.new }
|
7
|
+
|
8
|
+
describe ".apply_schema" do
|
9
|
+
before do
|
10
|
+
class MyDataModel < ActiveTriples::Schema
|
11
|
+
property :test_title, :predicate => RDF::DC.title
|
12
|
+
end
|
13
|
+
end
|
14
|
+
after do
|
15
|
+
Object.send(:remove_const, "MyDataModel")
|
16
|
+
end
|
17
|
+
it "should apply the schema" do
|
18
|
+
dummy_source.apply_schema MyDataModel
|
19
|
+
|
20
|
+
expect{dummy_source.new.test_title}.not_to raise_error
|
21
|
+
end
|
22
|
+
end
|
5
23
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ActiveTriples::Schema do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
describe ".property" do
|
7
|
+
it "should define a property" do
|
8
|
+
subject.property :title, :predicate => RDF::DC.title
|
9
|
+
|
10
|
+
property = subject.properties.first
|
11
|
+
expect(property.name).to eq :title
|
12
|
+
expect(property.predicate).to eq RDF::DC.title
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-triples
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Johnson
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdf
|
@@ -205,28 +205,34 @@ files:
|
|
205
205
|
- lib/active_triples/configuration/item.rb
|
206
206
|
- lib/active_triples/configuration/item_factory.rb
|
207
207
|
- lib/active_triples/configuration/merge_item.rb
|
208
|
+
- lib/active_triples/extension_strategy.rb
|
208
209
|
- lib/active_triples/identifiable.rb
|
209
210
|
- lib/active_triples/list.rb
|
210
211
|
- lib/active_triples/nested_attributes.rb
|
211
212
|
- lib/active_triples/node_config.rb
|
212
213
|
- lib/active_triples/properties.rb
|
214
|
+
- lib/active_triples/property.rb
|
213
215
|
- lib/active_triples/property_builder.rb
|
214
216
|
- lib/active_triples/rdf_source.rb
|
215
217
|
- lib/active_triples/reflection.rb
|
216
218
|
- lib/active_triples/relation.rb
|
217
219
|
- lib/active_triples/repositories.rb
|
218
220
|
- lib/active_triples/resource.rb
|
221
|
+
- lib/active_triples/schema.rb
|
219
222
|
- lib/active_triples/version.rb
|
220
223
|
- spec/active_triples/configurable_spec.rb
|
221
224
|
- spec/active_triples/configuration_spec.rb
|
225
|
+
- spec/active_triples/extension_strategy_spec.rb
|
222
226
|
- spec/active_triples/identifiable_spec.rb
|
223
227
|
- spec/active_triples/list_spec.rb
|
224
228
|
- spec/active_triples/nested_attributes_spec.rb
|
225
229
|
- spec/active_triples/properties_spec.rb
|
230
|
+
- spec/active_triples/property_spec.rb
|
226
231
|
- spec/active_triples/rdf_source_spec.rb
|
227
232
|
- spec/active_triples/relation_spec.rb
|
228
233
|
- spec/active_triples/repositories_spec.rb
|
229
234
|
- spec/active_triples/resource_spec.rb
|
235
|
+
- spec/active_triples/schema_spec.rb
|
230
236
|
- spec/active_triples_spec.rb
|
231
237
|
- spec/pragmatic_context_spec.rb
|
232
238
|
- spec/spec_helper.rb
|
@@ -251,7 +257,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
251
257
|
version: '0'
|
252
258
|
requirements: []
|
253
259
|
rubyforge_project:
|
254
|
-
rubygems_version: 2.
|
260
|
+
rubygems_version: 2.4.5
|
255
261
|
signing_key:
|
256
262
|
specification_version: 4
|
257
263
|
summary: RDF graphs in ActiveModel wrappers.
|