active-fedora 7.0.0.rc2 → 7.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -3
  3. data/CONTRIBUTORS.md +1 -0
  4. data/Gemfile +2 -3
  5. data/active-fedora.gemspec +4 -3
  6. data/gemfiles/rails3.gemfile +1 -7
  7. data/gemfiles/rails4.1.gemfile +5 -0
  8. data/gemfiles/rails4.gemfile +1 -6
  9. data/lib/active_fedora.rb +6 -6
  10. data/lib/active_fedora/associations/association_scope.rb +1 -1
  11. data/lib/active_fedora/base.rb +2 -0
  12. data/lib/active_fedora/datastream.rb +29 -2
  13. data/lib/active_fedora/datastream_collections.rb +2 -2
  14. data/lib/active_fedora/datastream_hash.rb +1 -1
  15. data/lib/active_fedora/datastreams.rb +4 -23
  16. data/lib/active_fedora/file_configurator.rb +8 -7
  17. data/lib/active_fedora/om_datastream.rb +1 -1
  18. data/lib/active_fedora/rdf.rb +9 -0
  19. data/lib/active_fedora/rdf/configurable.rb +59 -0
  20. data/lib/active_fedora/rdf/identifiable.rb +59 -0
  21. data/lib/active_fedora/rdf/indexing.rb +24 -23
  22. data/lib/active_fedora/rdf/list.rb +154 -0
  23. data/lib/active_fedora/{ntriples_rdf_datastream.rb → rdf/ntriples_rdf_datastream.rb} +0 -0
  24. data/lib/active_fedora/rdf/object_resource.rb +20 -0
  25. data/lib/active_fedora/rdf/properties.rb +108 -0
  26. data/lib/active_fedora/rdf/rdf_datastream.rb +113 -0
  27. data/lib/active_fedora/{rdfxml_rdf_datastream.rb → rdf/rdfxml_rdf_datastream.rb} +0 -0
  28. data/lib/active_fedora/rdf/repositories.rb +36 -0
  29. data/lib/active_fedora/rdf/resource.rb +324 -0
  30. data/lib/active_fedora/rdf/term.rb +188 -0
  31. data/lib/active_fedora/relation.rb +1 -0
  32. data/lib/active_fedora/relation/finder_methods.rb +16 -17
  33. data/lib/active_fedora/relation/merger.rb +1 -1
  34. data/lib/active_fedora/relation/query_methods.rb +13 -5
  35. data/lib/active_fedora/reload_on_save.rb +16 -0
  36. data/lib/active_fedora/rubydora_connection.rb +0 -1
  37. data/lib/active_fedora/sharding.rb +1 -1
  38. data/lib/active_fedora/version.rb +1 -1
  39. data/script/console +10 -11
  40. data/spec/config_helper.rb +1 -1
  41. data/spec/fixtures/solr_rdf_descMetadata.nt +1 -1
  42. data/spec/integration/auditable_spec.rb +1 -1
  43. data/spec/integration/base_spec.rb +21 -3
  44. data/spec/integration/complex_rdf_datastream_spec.rb +32 -55
  45. data/spec/integration/field_to_solr_name_spec.rb +6 -8
  46. data/spec/integration/has_many_associations_spec.rb +10 -3
  47. data/spec/integration/load_from_solr_spec.rb +15 -17
  48. data/spec/integration/ntriples_datastream_spec.rb +19 -23
  49. data/spec/integration/om_datastream_spec.rb +1 -1
  50. data/spec/integration/rdf_nested_attributes_spec.rb +51 -70
  51. data/spec/integration/relation_spec.rb +24 -11
  52. data/spec/integration/scoped_query_spec.rb +5 -1
  53. data/spec/samples/hydra-mods_article_datastream.rb +4 -0
  54. data/spec/samples/hydra-rights_metadata_datastream.rb +5 -0
  55. data/spec/samples/marpa-dc_datastream.rb +6 -1
  56. data/spec/samples/special_thing.rb +5 -5
  57. data/spec/spec_helper.rb +0 -3
  58. data/spec/support/an_active_model.rb +5 -12
  59. data/spec/unit/active_fedora_spec.rb +2 -2
  60. data/spec/unit/attributes_spec.rb +4 -8
  61. data/spec/unit/base_datastream_management_spec.rb +5 -29
  62. data/spec/unit/base_spec.rb +4 -0
  63. data/spec/unit/code_configurator_spec.rb +2 -2
  64. data/spec/unit/config_spec.rb +2 -2
  65. data/spec/unit/core_spec.rb +2 -4
  66. data/spec/unit/datastream_spec.rb +15 -0
  67. data/spec/unit/datastreams_spec.rb +1 -12
  68. data/spec/unit/file_configurator_spec.rb +1 -1
  69. data/spec/unit/ntriples_datastream_spec.rb +52 -57
  70. data/spec/unit/om_datastream_spec.rb +3 -3
  71. data/spec/unit/query_spec.rb +3 -4
  72. data/spec/unit/rdf_configurable_spec.rb +37 -0
  73. data/spec/unit/rdf_datastream_spec.rb +5 -7
  74. data/spec/unit/rdf_list_nested_attributes_spec.rb +22 -36
  75. data/spec/unit/rdf_list_spec.rb +26 -38
  76. data/spec/unit/rdf_properties_spec.rb +70 -0
  77. data/spec/unit/rdf_repositories_spec.rb +28 -0
  78. data/spec/unit/rdf_resource_datastream_spec.rb +287 -0
  79. data/spec/unit/rdf_resource_spec.rb +341 -0
  80. data/spec/unit/rdfxml_rdf_datastream_spec.rb +10 -26
  81. data/spec/unit/reload_on_save_spec.rb +24 -0
  82. data/spec/unit/solr_service_spec.rb +3 -3
  83. metadata +45 -16
  84. data/lib/active_fedora/rdf_datastream.rb +0 -113
  85. data/lib/active_fedora/rdf_list.rb +0 -162
  86. data/lib/active_fedora/rdf_node.rb +0 -332
  87. data/lib/active_fedora/rdf_node/term_proxy.rb +0 -141
  88. data/lib/active_fedora/rdf_object.rb +0 -24
  89. data/lib/active_fedora/yaml_adaptor.rb +0 -12
  90. data/spec/unit/rdf_node_spec.rb +0 -36
@@ -4,9 +4,7 @@ describe ActiveFedora::RdfxmlRDFDatastream do
4
4
  describe "a new instance" do
5
5
  before(:each) do
6
6
  class MyRdfxmlDatastream < ActiveFedora::RdfxmlRDFDatastream
7
- map_predicates do |map|
8
- map.publisher(:in => RDF::DC)
9
- end
7
+ property :publisher, :predicate => RDF::DC.publisher
10
8
  end
11
9
  @subject = MyRdfxmlDatastream.new(@inner_object, 'mixed_rdf')
12
10
  @subject.stub(:pid => 'test:1')
@@ -21,7 +19,7 @@ describe ActiveFedora::RdfxmlRDFDatastream do
21
19
  end
22
20
 
23
21
  describe "a complex data model" do
24
- before do
22
+ before do
25
23
  class DAMS < RDF::Vocabulary("http://library.ucsd.edu/ontology/dams#")
26
24
  property :title
27
25
  property :relatedTitle
@@ -46,16 +44,14 @@ describe ActiveFedora::RdfxmlRDFDatastream do
46
44
 
47
45
  module RDF
48
46
  # This enables RDF to respond_to? :value
49
- def self.value
47
+ def self.value
50
48
  self[:value]
51
49
  end
52
50
  end
53
51
 
54
52
  class MyDatastream < ActiveFedora::RdfxmlRDFDatastream
55
- map_predicates do |map|
56
- map.resource_type(:in => DAMS, :to => 'typeOfResource')
57
- map.title(:in => DAMS, :class_name => 'Description')
58
- end
53
+ property :resource_type, :predicate => DAMS.typeOfResource
54
+ property :title, :predicate => DAMS.title, :class_name => 'Description'
59
55
 
60
56
  rdf_subject { |ds| RDF::URI.new(ds.about) }
61
57
 
@@ -66,22 +62,10 @@ describe ActiveFedora::RdfxmlRDFDatastream do
66
62
  super
67
63
  end
68
64
 
69
- after_initialize :type_resource
70
- def type_resource
71
- graph.insert([RDF::URI.new(about), RDF.type, DAMS.Object])
72
- end
73
-
74
- def content=(content)
75
- super
76
- @about = graph.statements.first.subject
77
- end
78
- class Description
79
- include ActiveFedora::RdfObject
80
- map_predicates do |map|
81
- rdf_type DAMS.Description
82
- map.value(:in=> RDF) do |index|
65
+ class Description < ActiveFedora::Rdf::Resource
66
+ configure :type => DAMS.Description
67
+ property :value, :predicate => RDF.value do |index|
83
68
  index.as :searchable
84
- end
85
69
  end
86
70
  end
87
71
  end
@@ -97,12 +81,12 @@ describe ActiveFedora::RdfxmlRDFDatastream do
97
81
  it "should have a subject" do
98
82
  subject.rdf_subject.to_s.should == "http://library.ucsd.edu/ark:/20775/"
99
83
  end
100
-
84
+
101
85
  end
102
86
 
103
87
  describe "an instance with content" do
104
88
  subject do
105
- subject = MyDatastream.new(double('inner object', :pid=>'test:1', :new_record? =>true), 'descMetadata')
89
+ subject = MyDatastream.new(double('inner object', :pid=>'test:1', :new_record? =>true), 'descMetadata', about:"http://library.ucsd.edu/ark:/20775/")
106
90
  subject.content = File.new('spec/fixtures/damsObjectModel.xml').read
107
91
  subject
108
92
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveFedora::ReloadOnSave do
4
+ let(:file) { ActiveFedora::Base.new }
5
+
6
+ it 'defaults to call not reload' do
7
+ file.should_not_receive(:reload)
8
+ file.save
9
+ end
10
+
11
+ it 'reload can be turned on' do
12
+ file.reload_on_save = true
13
+ file.should_receive(:reload)
14
+ file.save
15
+ end
16
+
17
+ it 'allows reload to be turned off and on' do
18
+ file.reload_on_save = true
19
+ file.should_receive(:reload).once
20
+ file.save
21
+ file.reload_on_save = false
22
+ file.save
23
+ end
24
+ end
@@ -56,7 +56,7 @@ describe ActiveFedora::SolrService do
56
56
  end
57
57
  it "should use .load_instance_from_solr when called with :load_from_solr option" do
58
58
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits.first)
59
- ActiveFedora::SolrService.should_not receive(:query)
59
+ ActiveFedora::SolrService.should_not_receive(:query)
60
60
  ActiveFedora::SolrService.reify_solr_result(@sample_solr_hits.first, load_from_solr: true)
61
61
  end
62
62
  end
@@ -71,7 +71,7 @@ describe ActiveFedora::SolrService do
71
71
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits[0])
72
72
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID2_", @sample_solr_hits[1])
73
73
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID3_", @sample_solr_hits[2])
74
- ActiveFedora::SolrService.should_not receive(:query)
74
+ ActiveFedora::SolrService.should_not_receive(:query)
75
75
  ActiveFedora::SolrService.reify_solr_results(@sample_solr_hits, load_from_solr: true)
76
76
  end
77
77
  end
@@ -86,7 +86,7 @@ describe ActiveFedora::SolrService do
86
86
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID1_", @sample_solr_hits[0])
87
87
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID2_", @sample_solr_hits[1])
88
88
  AudioRecord.should_receive(:load_instance_from_solr).with("my:_PID3_", @sample_solr_hits[2])
89
- ActiveFedora::SolrService.should_not receive(:query)
89
+ ActiveFedora::SolrService.should_not_receive(:query)
90
90
  ActiveFedora::SolrService.lazy_reify_solr_results(@sample_solr_hits, load_from_solr: true).each {|r| r}
91
91
  end
92
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active-fedora
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0.rc2
4
+ version: 7.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-02-10 00:00:00.000000000 Z
13
+ date: 2014-03-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -88,16 +88,16 @@ dependencies:
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: 1.7.0
91
+ version: 1.7.4
92
92
  type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: 1.7.0
98
+ version: 1.7.4
99
99
  - !ruby/object:Gem::Dependency
100
- name: rdf
100
+ name: linkeddata
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - ">="
@@ -250,6 +250,20 @@ dependencies:
250
250
  - - ">="
251
251
  - !ruby/object:Gem::Version
252
252
  version: '0'
253
+ - !ruby/object:Gem::Dependency
254
+ name: simplecov
255
+ requirement: !ruby/object:Gem::Requirement
256
+ requirements:
257
+ - - "~>"
258
+ - !ruby/object:Gem::Version
259
+ version: 0.7.1
260
+ type: :development
261
+ prerelease: false
262
+ version_requirements: !ruby/object:Gem::Requirement
263
+ requirements:
264
+ - - "~>"
265
+ - !ruby/object:Gem::Version
266
+ version: 0.7.1
253
267
  description: ActiveFedora provides for creating and managing objects in the Fedora
254
268
  Repository Architecture.
255
269
  email:
@@ -280,6 +294,7 @@ files:
280
294
  - config/solr_mappings_af_0.1.yml
281
295
  - config/solr_mappings_bl_2.4.yml
282
296
  - gemfiles/rails3.gemfile
297
+ - gemfiles/rails4.1.gemfile
283
298
  - gemfiles/rails4.gemfile
284
299
  - lib/active-fedora.rb
285
300
  - lib/active_fedora.rb
@@ -324,7 +339,6 @@ files:
324
339
  - lib/active_fedora/model.rb
325
340
  - lib/active_fedora/nested_attributes.rb
326
341
  - lib/active_fedora/nom_datastream.rb
327
- - lib/active_fedora/ntriples_rdf_datastream.rb
328
342
  - lib/active_fedora/null_relation.rb
329
343
  - lib/active_fedora/om_datastream.rb
330
344
  - lib/active_fedora/persistence.rb
@@ -334,16 +348,21 @@ files:
334
348
  - lib/active_fedora/querying.rb
335
349
  - lib/active_fedora/railtie.rb
336
350
  - lib/active_fedora/rdf.rb
351
+ - lib/active_fedora/rdf/configurable.rb
352
+ - lib/active_fedora/rdf/identifiable.rb
337
353
  - lib/active_fedora/rdf/indexing.rb
354
+ - lib/active_fedora/rdf/list.rb
338
355
  - lib/active_fedora/rdf/nested_attributes.rb
339
356
  - lib/active_fedora/rdf/node_config.rb
340
- - lib/active_fedora/rdf_datastream.rb
341
- - lib/active_fedora/rdf_list.rb
342
- - lib/active_fedora/rdf_node.rb
343
- - lib/active_fedora/rdf_node/term_proxy.rb
344
- - lib/active_fedora/rdf_object.rb
357
+ - lib/active_fedora/rdf/ntriples_rdf_datastream.rb
358
+ - lib/active_fedora/rdf/object_resource.rb
359
+ - lib/active_fedora/rdf/properties.rb
360
+ - lib/active_fedora/rdf/rdf_datastream.rb
361
+ - lib/active_fedora/rdf/rdfxml_rdf_datastream.rb
362
+ - lib/active_fedora/rdf/repositories.rb
363
+ - lib/active_fedora/rdf/resource.rb
364
+ - lib/active_fedora/rdf/term.rb
345
365
  - lib/active_fedora/rdf_xml_writer.rb
346
- - lib/active_fedora/rdfxml_rdf_datastream.rb
347
366
  - lib/active_fedora/reflection.rb
348
367
  - lib/active_fedora/relation.rb
349
368
  - lib/active_fedora/relation/calculations.rb
@@ -353,6 +372,7 @@ files:
353
372
  - lib/active_fedora/relation/query_methods.rb
354
373
  - lib/active_fedora/relation/spawn_methods.rb
355
374
  - lib/active_fedora/relationship_graph.rb
375
+ - lib/active_fedora/reload_on_save.rb
356
376
  - lib/active_fedora/rels_ext_datastream.rb
357
377
  - lib/active_fedora/rspec_matchers.rb
358
378
  - lib/active_fedora/rspec_matchers/belong_to_associated_active_fedora_object_matcher.rb
@@ -375,7 +395,6 @@ files:
375
395
  - lib/active_fedora/unsaved_digital_object.rb
376
396
  - lib/active_fedora/validations.rb
377
397
  - lib/active_fedora/version.rb
378
- - lib/active_fedora/yaml_adaptor.rb
379
398
  - lib/generators/active_fedora/config/USAGE
380
399
  - lib/generators/active_fedora/config/config_generator.rb
381
400
  - lib/generators/active_fedora/config/fedora/fedora_generator.rb
@@ -496,13 +515,18 @@ files:
496
515
  - spec/unit/property_spec.rb
497
516
  - spec/unit/qualified_dublin_core_datastream_spec.rb
498
517
  - spec/unit/query_spec.rb
518
+ - spec/unit/rdf_configurable_spec.rb
499
519
  - spec/unit/rdf_datastream_spec.rb
500
520
  - spec/unit/rdf_list_nested_attributes_spec.rb
501
521
  - spec/unit/rdf_list_spec.rb
502
- - spec/unit/rdf_node_spec.rb
522
+ - spec/unit/rdf_properties_spec.rb
523
+ - spec/unit/rdf_repositories_spec.rb
524
+ - spec/unit/rdf_resource_datastream_spec.rb
525
+ - spec/unit/rdf_resource_spec.rb
503
526
  - spec/unit/rdf_xml_writer_spec.rb
504
527
  - spec/unit/rdfxml_rdf_datastream_spec.rb
505
528
  - spec/unit/relationship_graph_spec.rb
529
+ - spec/unit/reload_on_save_spec.rb
506
530
  - spec/unit/rels_ext_datastream_spec.rb
507
531
  - spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb
508
532
  - spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb
@@ -538,7 +562,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
538
562
  version: 1.3.1
539
563
  requirements: []
540
564
  rubyforge_project:
541
- rubygems_version: 2.2.1
565
+ rubygems_version: 2.2.2
542
566
  signing_key:
543
567
  specification_version: 4
544
568
  summary: A convenience libary for manipulating documents in the Fedora Repository.
@@ -640,13 +664,18 @@ test_files:
640
664
  - spec/unit/property_spec.rb
641
665
  - spec/unit/qualified_dublin_core_datastream_spec.rb
642
666
  - spec/unit/query_spec.rb
667
+ - spec/unit/rdf_configurable_spec.rb
643
668
  - spec/unit/rdf_datastream_spec.rb
644
669
  - spec/unit/rdf_list_nested_attributes_spec.rb
645
670
  - spec/unit/rdf_list_spec.rb
646
- - spec/unit/rdf_node_spec.rb
671
+ - spec/unit/rdf_properties_spec.rb
672
+ - spec/unit/rdf_repositories_spec.rb
673
+ - spec/unit/rdf_resource_datastream_spec.rb
674
+ - spec/unit/rdf_resource_spec.rb
647
675
  - spec/unit/rdf_xml_writer_spec.rb
648
676
  - spec/unit/rdfxml_rdf_datastream_spec.rb
649
677
  - spec/unit/relationship_graph_spec.rb
678
+ - spec/unit/reload_on_save_spec.rb
650
679
  - spec/unit/rels_ext_datastream_spec.rb
651
680
  - spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb
652
681
  - spec/unit/rspec_matchers/have_many_associated_active_fedora_objects_matcher_spec.rb
@@ -1,113 +0,0 @@
1
- module ActiveFedora
2
- class RDFDatastream < Datastream
3
-
4
- before_save do
5
- if content.blank?
6
- logger.warn "Cowardly refusing to save a datastream with empty content: #{self.inspect}"
7
- false
8
- end
9
- end
10
- include RdfNode
11
- include Rdf::Indexing
12
-
13
- class << self
14
- ##
15
- # Register a ruby block that evaluates to the subject of the graph
16
- # By default, the block returns the current object's pid
17
- # @yield [ds] 'ds' is the datastream instance
18
- # This should override the method in RdfObject, which just creates a b-node by default
19
- def rdf_subject &block
20
- if block_given?
21
- return @subject_block = block
22
- end
23
-
24
- @subject_block ||= lambda { |ds| RDF::URI.new("info:fedora/#{ds.pid}") }
25
- end
26
- end
27
-
28
- def freeze
29
- @graph.freeze
30
- end
31
-
32
- def metadata?
33
- true
34
- end
35
-
36
- # Overriding so that one can call ds.content on an unsaved datastream and they will see the serialized format
37
- def content
38
- serialize
39
- end
40
-
41
- def content=(content)
42
- reset_child_cache!
43
- @graph = deserialize(content)
44
- end
45
-
46
- def content_changed?
47
- # we haven't touched the graph, so it isn't changed (avoid a force load)
48
- return false unless instance_variable_defined? :@graph
49
- @content = serialize
50
- super
51
- end
52
- # Populate a RDFDatastream object based on the "datastream" content
53
- # Assumes that the datastream contains RDF content
54
- # @param [String] data the "rdf" node
55
- def deserialize(data = nil)
56
- repository = RDF::Repository.new
57
- return repository if new? and data.nil?
58
-
59
- data ||= datastream_content
60
- data.force_encoding('utf-8')
61
- RDF::Reader.for(serialization_format).new(data) do |reader|
62
- reader.each_statement do |statement|
63
- repository << statement
64
- end
65
- end
66
-
67
- repository
68
- end
69
-
70
- def graph
71
- @graph ||= begin
72
- deserialize
73
- end
74
- end
75
-
76
- def serialization_format
77
- raise "you must override the `serialization_format' method in a subclass"
78
- end
79
-
80
- # Creates a RDF datastream for insertion into a Fedora Object
81
- # Note: This method is implemented on SemanticNode instead of RelsExtDatastream because SemanticNode contains the relationships array
82
- def serialize
83
- update_subjects_to_use_a_real_pid!
84
-
85
- RDF::Writer.for(serialization_format).dump(graph)
86
- end
87
-
88
-
89
- private
90
-
91
- def update_subjects_to_use_a_real_pid!
92
- return unless new?
93
-
94
- bad_subject = rdf_subject
95
- reset_rdf_subject!
96
- reset_child_cache!
97
- new_subject = rdf_subject
98
-
99
- new_repository = RDF::Repository.new
100
-
101
- graph.each_statement do |statement|
102
- subject = statement.subject
103
-
104
- subject &&= new_subject if subject == bad_subject
105
- new_repository << [subject, statement.predicate, statement.object]
106
- end
107
-
108
- @graph = new_repository
109
- end
110
-
111
- end
112
- end
113
-
@@ -1,162 +0,0 @@
1
- module ActiveFedora
2
- module RdfList
3
- extend ActiveSupport::Concern
4
- include ActiveFedora::RdfNode
5
-
6
- attr_reader :graph, :subject
7
-
8
- # RdfList is a node of a linked list structure.
9
- # The RDF.first predicate points to the contained object
10
- # The RDF.rest predicate points to the next node in the list or
11
- # RDF.nil if this is the final node.
12
- # @see http://www.w3.org/TR/rdf-schema/#ch_list
13
- def initialize(graph, subject)
14
- @graph = graph
15
- @subject = subject
16
- first = graph.query([subject, RDF.first, nil]).first
17
- last = graph.query([subject, RDF.rest, nil]).first
18
- graph.insert([subject, RDF.first, RDF.nil]) unless first
19
- graph.insert([subject, RDF.rest, RDF.nil]) unless last
20
- end
21
-
22
- UNASSIGNABLE_KEYS = %w(_destroy )
23
-
24
- # Override assign_nested_attributes
25
- def assign_nested_attributes_for_collection_association(association_name, attributes_collection)
26
- options = self.nested_attributes_options[association_name]
27
-
28
- # TODO
29
- #check_record_limit!(options[:limit], attributes_collection)
30
-
31
- if attributes_collection.is_a?(Hash)
32
- attributes_collection = attributes_collection.values
33
- end
34
-
35
- association = self.send(association_name)
36
-
37
- original_length_of_list = self.size
38
- attributes_collection.each_with_index do |attributes, index|
39
- attributes = attributes.with_indifferent_access
40
- minted_node = association.mint_node(attributes.except(*UNASSIGNABLE_KEYS))
41
- self[original_length_of_list+index] = minted_node
42
- end
43
- end
44
-
45
-
46
- # Override the method from RdfNode, enabling us to insert into the list.
47
- def insert_child(predicate, node)
48
- self[size] = node
49
- end
50
-
51
- def rdf_subject
52
- subject
53
- end
54
-
55
- def first
56
- self[0]
57
- end
58
-
59
- def [](idx)
60
- idx == 0 ? head.value : tail[idx-1]
61
- end
62
-
63
- def []=(idx, value)
64
- idx == 0 ? head.value=value : tail_or_create(idx-1).value=value
65
- end
66
-
67
- def clear(first_element=true)
68
- # Remove the pointed at element
69
- v = graph.query([subject, RDF.first, nil]).first
70
- # TODO - Recursive delete
71
- graph.delete([v.object, nil, nil])
72
-
73
- # Remove the tail
74
- tail.clear(false) if tail
75
- # clear the cache
76
- @tail = nil
77
- graph.delete([subject, nil, nil])
78
- if first_element
79
- # Re-add first/rest predicates if its the first node
80
- graph.insert([subject, RDF.first, RDF.nil])
81
- graph.insert([subject, RDF.rest, RDF.nil])
82
- end
83
- end
84
-
85
- def each &block
86
- yield(head.value)
87
- tail.each(&block) if tail
88
- end
89
-
90
- def to_ary
91
- if empty?
92
- []
93
- elsif tail
94
- [head.value] + tail.to_ary
95
- else
96
- [head.value]
97
- end
98
- end
99
-
100
- def empty?
101
- !tail && graph.query([subject, RDF.first, RDF.nil]).first
102
- end
103
-
104
- def size
105
- if empty?
106
- 0
107
- elsif tail
108
- tail.size + 1
109
- else
110
- 1
111
- end
112
- end
113
-
114
- def inspect
115
- "[ #{value ? value.inspect : 'nil'}, #{tail.inspect}]"
116
- end
117
-
118
- def value
119
- v = graph.query([subject, RDF.first, nil]).first
120
- if v.object.uri?
121
- return v.object == RDF.nil ? nil : v.object
122
- end
123
- if v.object.resource?
124
- type = graph.query([v.object, RDF.type, nil]).first
125
- return ActiveFedora::RdfNode.rdf_registry[type.object].new(graph, v.object)
126
- end
127
- v
128
- end
129
-
130
- def value=(obj)
131
- graph.delete([subject, RDF.first, RDF.nil])
132
- if obj.respond_to? :rdf_subject
133
- graph.insert([subject, RDF.first, obj.rdf_subject]) # an ActiveFedora::RdfObject
134
- else
135
- graph.insert([subject, RDF.first, obj])
136
- end
137
- end
138
-
139
- def head
140
- @head ||= self.class.new(graph, subject)
141
- end
142
-
143
- def tail
144
- return @tail if @tail
145
- rest = graph.query([subject, RDF.rest, nil]).first
146
- return if rest.object == RDF.nil
147
- @tail = self.class.new(graph, rest.object)
148
- end
149
-
150
- def tail_or_create(idx)
151
- unless tail
152
- #add a tail
153
- graph.delete([subject, RDF.rest, RDF.nil])
154
- tail_node = RDF::Node.new
155
- graph.insert([subject, RDF.rest, tail_node])
156
- @tail = self.class.new(graph, tail_node)
157
- end
158
-
159
- idx == 0 ? @tail : @tail.tail_or_create(idx-1)
160
- end
161
- end
162
- end