active-triples 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4dc6967bd4ea18668b379926f3504e0c67c5135
4
- data.tar.gz: c75e487fcf484d7e1f91a7a919ac9c56c2728c1b
3
+ metadata.gz: a8509c08a01f7e74117e8ea5791aaf2728360c80
4
+ data.tar.gz: f1941f479ed0e56364c957497e8d8f39403b6efa
5
5
  SHA512:
6
- metadata.gz: d548a15c50003b4625c33283399bd8d101edceec9671658012b1702cead051c7230188afe2a6100feb9bd93c3a08204bbd4395266fec6aebc071863e3e647b28
7
- data.tar.gz: c2a1f637cd7a4edf4a9a3eb3fd78fcbf143e964561d6648d674353575a4c5312aee21f8502de003b4ae1a4bbb4c7f13760eabbdfe35d126ef9f312e9efd14775
6
+ metadata.gz: faff9891e25d5962d178cf88baceaaaf0b40b8f0d0bca6538d15421834f6529d00cdbe5e5995e1cfef868a8f593a1a2e84aa3309b3cb933ee7e5192333fcfc4c
7
+ data.tar.gz: 76ef886b46c6cafb1f24a64df413a7d2f8d08aff2e97e2821cbca91e827bd03089eb337ace703aacf774d774b764c5320de891dd88320468608c408c079b214f
@@ -1,4 +1,4 @@
1
- anguage: ruby
1
+ language: ruby
2
2
  bundler_args: --without debug
3
3
  script: "bundle exec rspec spec"
4
4
  sudo: false
@@ -14,3 +14,4 @@ rvm:
14
14
  matrix:
15
15
  allow_failures:
16
16
  - rvm: jruby
17
+ - rvm: ruby-head
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.7.1
2
+ ----
3
+
4
+ - Adds a Schema concept, for defining property definitions that are portable
5
+ across RDFSource types.
6
+
1
7
  0.7.0
2
8
  -----
3
9
 
@@ -18,6 +18,9 @@ module ActiveTriples
18
18
  autoload :NestedAttributes
19
19
  autoload :Identifiable
20
20
  autoload :Configuration
21
+ autoload :Schema
22
+ autoload :Property
23
+ autoload :ExtensionStrategy
21
24
 
22
25
  # deprecated class
23
26
  autoload :Term, 'active_triples/relation'
@@ -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
@@ -1,3 +1,3 @@
1
1
  module ActiveTriples
2
- VERSION = "0.7.0".freeze
2
+ VERSION = "0.7.1".freeze
3
3
  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 described_class } }
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.0
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-05-14 00:00:00.000000000 Z
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.2.1
260
+ rubygems_version: 2.4.5
255
261
  signing_key:
256
262
  specification_version: 4
257
263
  summary: RDF graphs in ActiveModel wrappers.