active-triples 1.1.1 → 1.2.0

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
  SHA256:
3
- metadata.gz: b0ff972e1b4c29224d95c3b805194625adb62bd2e0b2f8e6bc10dce62fb048d0
4
- data.tar.gz: b53c8cc0662587141709428bd6bb4aa522ddd24387d1b10807202c23a1e66554
3
+ metadata.gz: 6c0e9d67f468229ed99433d744dde2215e21e5571e19b081bcb0a8edd5f42380
4
+ data.tar.gz: 4a33d1eeedc668e14402e1dbe5507b914427b3eef9b651d72226e53652465a9f
5
5
  SHA512:
6
- metadata.gz: 1cb53a7845d93423d84bdac4fa82b6470f28867ee5cf8c4bc04f8ba5a3046cc3b6c6f34f8ef2a04aa211c880a7c55700e68cbfc3a73729382a5e4409933b4dd6
7
- data.tar.gz: 279c0e2236bf9ad69aefc7e8e3e41e697431b8b103e548cc75b0985eeac1237e598f5fe89da71f9e4d86bad92bec84d4ab94b51c1a0798eb149021b0068d350f
6
+ metadata.gz: c54cf20963fc02882da7848b480653392fe5051ada1311bf04572556507978c7eda8ce4b2102a035faf315b399d3708ba6cfcd02eafedcccccf470aed2c65ef3
7
+ data.tar.gz: 278a128edabab0162e5dea4df901b7ecfd83bbf3c62820f8b65d447304edcc662ab93115cb1f2b9527fa64377708e00c6c3f0e8accc7dd79a361e8a937136db0
data/.gitlab-ci.yml CHANGED
@@ -36,6 +36,26 @@ ruby-2-7:
36
36
  extends: .rspec
37
37
  stage: test
38
38
 
39
+ ruby-3-0:
40
+ image: ruby:3.0
41
+ extends: .rspec
42
+ stage: test
43
+ before_script:
44
+ - ruby -v
45
+ - gem install bundler
46
+ - gem update --system
47
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
48
+
49
+ ruby-3-1:
50
+ image: ruby:3.1
51
+ extends: .rspec
52
+ stage: test
53
+
54
+ ruby-3-2:
55
+ image: ruby:3.2
56
+ extends: .rspec
57
+ stage: test
58
+
39
59
  ruby-latest:
40
60
  image: ruby:latest
41
61
  extends: .rspec
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ 1.2.0
2
+ ----
3
+ - Add support for Ruby 3.0, 3.1 and 3.2.
4
+ - Implemented `RDFSource#term?` for compatibility with current
5
+ `RDF::Enumerable` behavior.
6
+
1
7
  1.1.1
2
8
  ----
3
9
  - Major performance improvements due to a minor change in how
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ gemspec
5
5
  gem 'pry-byebug' unless ENV["CI"]
6
6
 
7
7
  group :test do
8
- gem 'rdf-spec', github: 'ruby-rdf/rdf-spec', branch: 'develop'
9
8
  gem 'simplecov', require: false
10
9
  end
11
10
 
@@ -6,9 +6,9 @@ Gem::Specification.new do |s|
6
6
  s.name = "active-triples"
7
7
  s.version = ActiveTriples::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Tom Johnson", "Trey Terrell"]
9
+ s.authors = ["Tamsin Johnson", "Trey Pendragon"]
10
10
  s.homepage = 'https://gitlab.com/no_reply/ActiveTriples'
11
- s.email = 'tom@curationexperts.com'
11
+ s.email = 'tomjohnson@ucsb.edu'
12
12
  s.summary = %q{RDF graphs in ActiveModel wrappers.}
13
13
  s.description = %q{ActiveTriples provides tools for modeling RDF as discrete resources.}
14
14
  s.license = 'Apache-2.0'
@@ -11,10 +11,11 @@ module ActiveTriples
11
11
 
12
12
  ##
13
13
  # @param item_factory [ItemFactory]
14
- # @param [Hash] options the configuration options.
15
- def initialize(item_factory: ItemFactory.new, **options)
14
+ # @param [Hash] options the configuration options. (Ruby 3+)
15
+ # @param [Hash] options2 the configuration options. (Ruby 2.x)
16
+ def initialize(options = {}, item_factory: ItemFactory.new, **options2)
16
17
  @item_factory = item_factory
17
- @inner_hash = Hash[options.to_a]
18
+ @inner_hash = Hash[options.to_a + options2.to_a]
18
19
  end
19
20
 
20
21
  ##
@@ -26,7 +27,7 @@ module ActiveTriples
26
27
  # result of merging.
27
28
  def merge(options)
28
29
  options = options.to_h
29
- new_config = self.class.new(**options)
30
+ new_config = self.class.new(options)
30
31
 
31
32
  new_config.items.each do |property, item|
32
33
  build_configuration_item(property).set item.value
@@ -52,7 +52,7 @@ module ActiveTriples
52
52
  #
53
53
  # @return [Boolean]
54
54
  def reload
55
- source << repository.query(subject: source)
55
+ source << repository.query([source, nil, nil])
56
56
  @persisted = true unless source.empty?
57
57
  true
58
58
  end
@@ -66,7 +66,7 @@ module ActiveTriples
66
66
  registered_preds = registered_predicates << RDF.type
67
67
  unregistered_preds = []
68
68
 
69
- query(subject: rdf_subject) do |stmt|
69
+ query([rdf_subject, nil, nil]) do |stmt|
70
70
  unregistered_preds << stmt.predicate unless
71
71
  registered_preds.include? stmt.predicate
72
72
  end
@@ -92,11 +92,9 @@ module ActiveTriples
92
92
  ##
93
93
  # @!method to_base
94
94
  # @return (see RDF::Term#to_base)
95
- # @!method term?
96
- # @return (see RDF::Term#term?)
97
95
  # @!method escape
98
96
  # @return (see RDF::Term#escape)
99
- delegate :to_base, :term?, :escape, to: :to_term
97
+ delegate :to_base, :escape, to: :to_term
100
98
 
101
99
  ##
102
100
  # Initialize an instance of this resource class. Defaults to a
@@ -110,7 +108,7 @@ module ActiveTriples
110
108
  # @see RDF::Graph
111
109
  # @todo move this logic out to a Builder?
112
110
  def initialize(*args, &block)
113
- @observers = Set.new
111
+ @observers = Set.new
114
112
 
115
113
  resource_uri = args.shift unless args.first.is_a?(Hash)
116
114
  @rdf_subject = get_uri(resource_uri) if resource_uri
@@ -122,7 +120,12 @@ module ActiveTriples
122
120
  persistence_strategy.parent = args.shift
123
121
  end
124
122
 
125
- persistence_strategy.graph = RDF::Graph.new(*args, &block)
123
+ graph_params = if args.empty? || args.first.nil?
124
+ {}
125
+ else
126
+ args.shift
127
+ end
128
+ persistence_strategy.graph = RDF::Graph.new(**graph_params, &block)
126
129
  reload
127
130
 
128
131
  # Append type to graph if necessary.
@@ -398,9 +401,9 @@ module ActiveTriples
398
401
  # @yieldparam [ActiveTriples::RDFSource] resource self
399
402
  #
400
403
  # @return [ActiveTriples::RDFSource] self
401
- def fetch(*args, &_block)
404
+ def fetch(**args, &_block)
402
405
  begin
403
- load(rdf_subject, *args)
406
+ load(rdf_subject, **args)
404
407
  rescue => e
405
408
  if block_given?
406
409
  yield(self)
@@ -575,6 +578,26 @@ module ActiveTriples
575
578
  !persisted?
576
579
  end
577
580
 
581
+ ##
582
+ # @overload term?
583
+ # Returns `false` indicating this is not an RDF::Statemenet.
584
+ # @see RDF::Value#statement?
585
+ # @return [Boolean]
586
+ # @overload term?(value)
587
+ # Returns `true` if `self` contains the given RDF subject term.
588
+ #
589
+ # @param [RDF::Resource] value
590
+ # @return [Boolean]
591
+ #
592
+ # See RDF::Enumerable#term?
593
+ def term?(*args)
594
+ case args.length
595
+ when 0 then to_term.term?
596
+ when 1 then args.first && graph.term?(args.first)
597
+ else raise ArgumentError("wrong number of arguments (given #{args.length}, expected 0 or 1)")
598
+ end
599
+ end
600
+
578
601
  def mark_for_destruction
579
602
  @marked_for_destruction = true
580
603
  end
@@ -641,7 +664,7 @@ module ActiveTriples
641
664
  # @param [RDF::Term] new_subject
642
665
  # @return [void]
643
666
  def rewrite_statement_uris(old_subject, new_subject)
644
- graph.query(subject: old_subject).each do |st|
667
+ graph.query([old_subject, nil, nil]).each do |st|
645
668
  graph.delete(st)
646
669
 
647
670
  st.subject = new_subject
@@ -649,7 +672,7 @@ module ActiveTriples
649
672
  graph.insert(st)
650
673
  end
651
674
 
652
- graph.query(object: old_subject).each do |st|
675
+ graph.query([nil, nil, old_subject]).each do |st|
653
676
  graph.delete(st)
654
677
 
655
678
  st.object = new_subject
@@ -481,7 +481,7 @@ module ActiveTriples
481
481
  ##
482
482
  # @private
483
483
  def objects(&block)
484
- solutions = parent.query(subject: rdf_subject, predicate: predicate)
484
+ solutions = parent.query([rdf_subject, predicate, nil])
485
485
  solutions.extend(RDF::Enumerable) unless solutions.respond_to?(:each_object)
486
486
 
487
487
  solutions.each_object(&block)
@@ -55,7 +55,7 @@ module ActiveTriples
55
55
  ancestors = @ancestors.dup
56
56
 
57
57
  if block_given?
58
- statements = source_graph.query(subject: starting_node).each
58
+ statements = source_graph.query([starting_node, nil, nil]).each
59
59
  statements.each_statement { |st| yield st }
60
60
 
61
61
  ancestors << starting_node
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ActiveTriples
3
- VERSION = '1.1.1'.freeze
3
+ VERSION = '1.2.0'.freeze
4
4
  end
@@ -743,7 +743,7 @@ describe ActiveTriples::RDFSource do
743
743
 
744
744
  it 'has errors' do
745
745
  expect { subject.valid? }
746
- .to change { subject.errors.messages }
746
+ .to change { subject.errors.messages.transform_values { |v| v.map(&:to_s) } }
747
747
  .from({})
748
748
  .to(include(base: ['The underlying graph must be valid']))
749
749
  end
@@ -470,7 +470,7 @@ describe ActiveTriples::Resource do
470
470
  describe '#set_value' do
471
471
  it 'should set a value in the graph' do
472
472
  subject.set_value(RDF::Vocab::DC.title, 'Comet in Moominland')
473
- subject.query(:subject => subject.rdf_subject, :predicate => RDF::Vocab::DC.title).each_statement do |s|
473
+ subject.query([subject.rdf_subject, nil, RDF::Vocab::DC.title]).each_statement do |s|
474
474
  expect(s.object.to_s).to eq 'Comet in Moominland'
475
475
  end
476
476
  end
@@ -522,14 +522,14 @@ describe ActiveTriples::Resource do
522
522
 
523
523
  it "should be able to accept a subject" do
524
524
  expect{subject.set_value(RDF::URI("http://opaquenamespace.org/jokes"), RDF::Vocab::DC.title, 'Comet in Moominland')}.not_to raise_error
525
- expect(subject.query(:subject => RDF::URI("http://opaquenamespace.org/jokes"), :predicate => RDF::Vocab::DC.title).statements.to_a.length).to eq 1
525
+ expect(subject.query([RDF::URI("http://opaquenamespace.org/jokes"), RDF::Vocab::DC.title, nil]).statements.to_a.length).to eq 1
526
526
  end
527
527
  end
528
528
 
529
529
  describe '#[]=' do
530
530
  it 'should set a value in the graph' do
531
531
  subject[RDF::Vocab::DC.title] = 'Comet in Moominland'
532
- subject.query(:subject => subject.rdf_subject, :predicate => RDF::Vocab::DC.title).each_statement do |s|
532
+ subject.query([subject.rdf_subject, nil, RDF::Vocab::DC.title]).each_statement do |s|
533
533
  expect(s.object.to_s).to eq 'Comet in Moominland'
534
534
  end
535
535
  end
@@ -616,7 +616,7 @@ describe ActiveTriples::Resource do
616
616
  end
617
617
 
618
618
  it 'should be the type in the graph' do
619
- subject.query(:subject => subject.rdf_subject, :predicate => RDF.type).statements do |s|
619
+ subject.query([subject.rdf_subject, nil, RDF.type]).statements do |s|
620
620
  expect(s.object).to eq RDF::URI('http://example.org/AnotherClass')
621
621
  end
622
622
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-triples
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Tom Johnson
8
- - Trey Terrell
7
+ - Tamsin Johnson
8
+ - Trey Pendragon
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-18 00:00:00.000000000 Z
12
+ date: 2023-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdf
@@ -252,7 +252,7 @@ dependencies:
252
252
  - !ruby/object:Gem::Version
253
253
  version: 0.1.2
254
254
  description: ActiveTriples provides tools for modeling RDF as discrete resources.
255
- email: tom@curationexperts.com
255
+ email: tomjohnson@ucsb.edu
256
256
  executables: []
257
257
  extensions: []
258
258
  extra_rdoc_files:
@@ -353,7 +353,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
353
353
  - !ruby/object:Gem::Version
354
354
  version: '0'
355
355
  requirements: []
356
- rubygems_version: 3.1.2
356
+ rubygems_version: 3.1.6
357
357
  signing_key:
358
358
  specification_version: 4
359
359
  summary: RDF graphs in ActiveModel wrappers.