active-triples 0.10.1 → 0.10.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c81332a8a8d648a2ee9e0452b03365379513735
4
- data.tar.gz: 025e5a4b382f9afc0f585d0f1131134ac9c873af
3
+ metadata.gz: 81641abcbc05748cde5355e096ae5707b933247d
4
+ data.tar.gz: 8700dd892403ce3907494e0ed4ab88375b914ccc
5
5
  SHA512:
6
- metadata.gz: 5db5e244b3a74c98e2d2e420889db1524d94752f0bc91d4f0e3306f3e96b110a19508a61845329b2e066d48b5b016d4f2fd1b9d2415ea4fd867b414a648113e4
7
- data.tar.gz: a696ec00b77357e264e452709dfef2f33eec1bf212792e349f9ba5b185246c0003261a38b22ce36310588be7d2493c2005e124046214f230d74e9cedbd076927
6
+ metadata.gz: 210be0186ab5dc6e88714b1be1b789662f83246333289cfd3408ae831ad17b3032a037ba13b1068453fdca0eddb110d73fe61d4babf0fb1e76480c4d7670ea2c
7
+ data.tar.gz: 7ed12d5c4348d46c6e3f70874e3067292e7ddda3edd63be388ab94b0a9c2abf6ce2e1a1c211dfbafdb598bd3e4a9a7c00aed109020d5a174186c685acbef3048
data/CHANGES.md CHANGED
@@ -1,3 +1,12 @@
1
+ 0.10.2
2
+ ----
3
+ - Backports several performance optimizations from the upcoming 0.11.x
4
+ release series.
5
+ - Uses `#query` to find unregistered predicates, avoiding iterating through
6
+ all statements.
7
+ - Uses a transaction to batch commit changes when calling `#set_subject!`
8
+ - Removes the `deprecation` gem as a runtime dependency
9
+
1
10
  0.10.1
2
11
  ----
3
12
  - Remove dependency on the `linkeddata` metagem
@@ -17,7 +17,6 @@ Gem::Specification.new do |s|
17
17
  s.add_dependency 'rdf', '~> 2.0', '>= 2.0.2'
18
18
  s.add_dependency 'rdf-vocab'
19
19
  s.add_dependency 'activemodel', '>= 3.0.0'
20
- s.add_dependency 'deprecation', '~> 1.0'
21
20
  s.add_dependency 'activesupport', '>= 3.0.0'
22
21
 
23
22
  s.add_development_dependency 'rdoc'
@@ -1,5 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'deprecation'
3
2
  require 'active_support/core_ext/array/wrap'
4
3
 
5
4
  module ActiveTriples
@@ -15,7 +14,6 @@ module ActiveTriples
15
14
  #
16
15
  # Available properties are base_uri, rdf_label, type, and repository
17
16
  module Configurable
18
- extend Deprecation
19
17
  def base_uri
20
18
  configuration[:base_uri]
21
19
  end
@@ -25,12 +25,6 @@ module ActiveTriples
25
25
  def destroy(&block)
26
26
  yield if block_given?
27
27
 
28
- # Provide a warning for strategies relying on #destroy to clear the resource
29
- if defined? obj
30
- warn "DEPRECATION WARNING: #destroy implementations must now explicitly call 'source.clear'"
31
- obj.clear
32
- end
33
-
34
28
  persist!
35
29
  @destroyed = true
36
30
  end
@@ -92,14 +92,15 @@ module ActiveTriples
92
92
  def initialize(*args, &block)
93
93
  resource_uri = args.shift unless args.first.is_a?(Hash)
94
94
  @rdf_subject = get_uri(resource_uri) if resource_uri
95
+
95
96
  unless args.first.is_a?(Hash) || args.empty?
96
97
  set_persistence_strategy(ParentStrategy)
97
98
  persistence_strategy.parent = args.shift
98
99
  else
99
100
  set_persistence_strategy(RepositoryStrategy)
100
101
  end
101
- @graph = RDF::Graph.new(*args, &block)
102
102
 
103
+ @graph = RDF::Graph.new(*args, &block)
103
104
  reload
104
105
 
105
106
  # Append type to graph if necessary.
@@ -496,32 +497,28 @@ module ActiveTriples
496
497
  ##
497
498
  # Set a new rdf_subject for the resource.
498
499
  #
499
- # This raises an error if the current subject is not a blank node,
500
- # and returns false if it can't figure out how to make a URI from
501
- # the param. Otherwise it creates a URI for the resource and
502
- # rebuilds the graph with the updated URI.
503
- #
504
500
  # Will try to build a uri as an extension of the class's base_uri
505
501
  # if appropriate.
506
502
  #
507
- # @param [#to_uri, #to_s] uri_or_str the uri or string to use
503
+ # @param [#to_uri, #to_s] uri_or_str the uri or string to use
504
+ # @return [void]
505
+ #
506
+ # @raise if the current subject is not a blank node,
507
+ # and returns false if it can't figure out how to make a URI from
508
+ # the param. Otherwise it creates a URI for the resource and
509
+ # rebuilds the graph with the updated URI.
508
510
  def set_subject!(uri_or_str)
509
- raise "Refusing update URI when one is already assigned!" unless node? or rdf_subject == RDF::URI(nil)
510
- # Refusing set uri to an empty string.
511
- return false if uri_or_str.nil? or (uri_or_str.to_s.empty? and not uri_or_str.kind_of? RDF::URI)
512
- # raise "Refusing update URI! This object is persisted to a datastream." if persisted?
513
- old_subject = rdf_subject
514
- @rdf_subject = get_uri(uri_or_str)
515
-
516
- each_statement do |statement|
517
- if statement.subject == old_subject
518
- delete(statement)
519
- self << RDF::Statement.new(rdf_subject, statement.predicate, statement.object)
520
- elsif statement.object == old_subject
521
- delete(statement)
522
- self << RDF::Statement.new(statement.subject, statement.predicate, rdf_subject)
523
- end
524
- end
511
+ raise "Refusing update URI when one is already assigned!" unless
512
+ node? || rdf_subject == RDF::URI(nil)
513
+
514
+ return false if uri_or_str.nil? ||
515
+ (uri_or_str.to_s.empty? &&
516
+ !uri_or_str.kind_of?(RDF::URI))
517
+
518
+ new_subject = get_uri(uri_or_str)
519
+ rewrite_statement_uris(rdf_subject, new_subject)
520
+
521
+ @rdf_subject = new_subject
525
522
  end
526
523
 
527
524
  ##
@@ -589,7 +586,12 @@ module ActiveTriples
589
586
  registered_preds = registered_predicates
590
587
  registered_preds << RDF.type
591
588
  unregistered_preds = []
592
- each_statement { |s,p,o| unregistered_preds << p unless (s != rdf_subject) || (registered_preds.include? p) }
589
+
590
+ query(subject: rdf_subject) do |stmt|
591
+ unregistered_preds << stmt.predicate unless
592
+ registered_preds.include? stmt.predicate
593
+ end
594
+
593
595
  unregistered_preds
594
596
  end
595
597
 
@@ -601,6 +603,33 @@ module ActiveTriples
601
603
  RDF::Vocab::SKOS.hiddenLabel]
602
604
  end
603
605
 
606
+ ##
607
+ # Rewrites the subject and object of each statement containing
608
+ # `old_subject` in either position. Used when setting the subject to
609
+ # remove the placeholder blank node subjects.
610
+ #
611
+ # @param [RDF::Term] old_subject
612
+ # @param [RDF::Term] new_subject
613
+ # @return [void]
614
+ def rewrite_statement_uris(old_subject, new_subject)
615
+ graph.transaction(mutable: true) do |tx|
616
+ tx.query(subject: old_subject).each do |st|
617
+ tx.delete(st)
618
+
619
+ st.subject = new_subject
620
+ st.object = new_subject if st.object == old_subject
621
+ tx.insert(st)
622
+ end
623
+
624
+ tx.query(object: old_subject).each do |st|
625
+ tx.delete(st)
626
+
627
+ st.object = new_subject
628
+ tx.insert(st)
629
+ end
630
+ end
631
+ end
632
+
604
633
  ##
605
634
  # Takes a URI or String and aggressively tries to convert it into
606
635
  # an RDF term. If a String is given, first tries to interpret it
@@ -1,6 +1,4 @@
1
1
  # frozen_string_literal: true
2
- require 'deprecation'
3
-
4
2
  module ActiveTriples
5
3
  ##
6
4
  # Defines a generic RDF `Resource` as an `ActiveTriples::Entity`. This
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveTriples
3
- VERSION = '0.10.1'.freeze
3
+ VERSION = '0.10.2'.freeze
4
4
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe ActiveTriples::UndefinedPropertyError do
5
+ subject { described_class.new(property, klass) }
6
+
7
+ let(:property) { :a_property }
8
+ let(:klass) { :a_class }
9
+
10
+ it { expect(subject.message).to be_a String }
11
+
12
+ it { expect(subject.property).to eq property }
13
+ it { expect(subject.klass).to eq klass }
14
+ end
15
+
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require "spec_helper"
3
+
4
+ describe ActiveTriples::Relation::ValueError do
5
+ subject { described_class.new(value) }
6
+
7
+ let(:value) { :a_value }
8
+
9
+ it { expect(subject.message).to be_a String }
10
+ it { expect(subject.value).to eq value }
11
+ 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.10.1
4
+ version: 0.10.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Johnson
@@ -59,20 +59,6 @@ dependencies:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 3.0.0
62
- - !ruby/object:Gem::Dependency
63
- name: deprecation
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.0'
69
- type: :runtime
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.0'
76
62
  - !ruby/object:Gem::Dependency
77
63
  name: activesupport
78
64
  requirement: !ruby/object:Gem::Requirement
@@ -292,6 +278,8 @@ files:
292
278
  - spec/active_triples/repositories_spec.rb
293
279
  - spec/active_triples/resource_spec.rb
294
280
  - spec/active_triples/schema_spec.rb
281
+ - spec/active_triples/undefined_property_error_spec.rb
282
+ - spec/active_triples/value_error_spec.rb
295
283
  - spec/active_triples_spec.rb
296
284
  - spec/integration/dummies/dummy_resource_a.rb
297
285
  - spec/integration/dummies/dummy_resource_b.rb