active-fedora 11.0.0.rc6 → 11.0.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/active-fedora.gemspec +0 -3
  3. data/lib/active_fedora.rb +0 -10
  4. data/lib/active_fedora/associations/has_many_association.rb +1 -1
  5. data/lib/active_fedora/attributes.rb +1 -1
  6. data/lib/active_fedora/base.rb +3 -7
  7. data/lib/active_fedora/querying.rb +1 -1
  8. data/lib/active_fedora/rdf.rb +0 -1
  9. data/lib/active_fedora/version.rb +1 -1
  10. data/spec/integration/attached_files_spec.rb +14 -4
  11. data/spec/integration/file_spec.rb +22 -23
  12. data/spec/integration/versionable_spec.rb +0 -254
  13. data/spec/spec_helper.rb +0 -7
  14. data/spec/unit/attached_files_spec.rb +10 -7
  15. data/spec/unit/base_spec.rb +3 -1
  16. data/spec/unit/has_many_association_spec.rb +23 -8
  17. data/spec/unit/inheritance_spec.rb +11 -7
  18. data/spec/unit/model_classifier_spec.rb +1 -1
  19. data/spec/unit/rdf/indexing_service_spec.rb +9 -9
  20. data/spec/unit/solr_config_options_spec.rb +12 -15
  21. metadata +2 -67
  22. data/lib/active_fedora/datastreams.rb +0 -6
  23. data/lib/active_fedora/datastreams/nokogiri_datastreams.rb +0 -119
  24. data/lib/active_fedora/nom_datastream.rb +0 -73
  25. data/lib/active_fedora/om_datastream.rb +0 -118
  26. data/lib/active_fedora/qualified_dublin_core_datastream.rb +0 -158
  27. data/lib/active_fedora/rdf/datastream_indexing.rb +0 -49
  28. data/lib/active_fedora/rdf/ntriples_rdf_datastream.rb +0 -13
  29. data/lib/active_fedora/rdf/rdf_datastream.rb +0 -173
  30. data/lib/active_fedora/rdf/rdfxml_datastream.rb +0 -13
  31. data/spec/integration/complex_rdf_datastream_spec.rb +0 -227
  32. data/spec/integration/datastream_rdf_nested_attributes_spec.rb +0 -180
  33. data/spec/integration/ntriples_datastream_spec.rb +0 -215
  34. data/spec/integration/om_datastream_spec.rb +0 -78
  35. data/spec/samples/hydra-mods_article_datastream.rb +0 -515
  36. data/spec/samples/models/mods_article.rb +0 -9
  37. data/spec/samples/samples.rb +0 -2
  38. data/spec/unit/nom_datastream_spec.rb +0 -60
  39. data/spec/unit/ntriples_datastream_spec.rb +0 -167
  40. data/spec/unit/om_datastream_spec.rb +0 -294
  41. data/spec/unit/qualified_dublin_core_datastream_spec.rb +0 -119
  42. data/spec/unit/rdf_datastream_spec.rb +0 -84
  43. data/spec/unit/rdf_resource_datastream_spec.rb +0 -208
  44. data/spec/unit/rdfxml_datastream_spec.rb +0 -106
@@ -24,7 +24,6 @@ ActiveFedora::Base.logger.level = Logger::WARN
24
24
  # HttpLogger.log_headers = true
25
25
 
26
26
  Dir[File.expand_path("../support/**/*.rb", __FILE__)].each { |f| require f }
27
- require 'samples/samples'
28
27
 
29
28
  $VERBOSE = nil
30
29
 
@@ -37,12 +36,6 @@ restore_spec_configuration
37
36
 
38
37
  require 'active_fedora/cleaner'
39
38
  RSpec.configure do |config|
40
- config.before(:suite) do
41
- ActiveFedora::RDFDatastream.deprecation_behavior = :silence
42
- ActiveFedora::NtriplesRDFDatastream.deprecation_behavior = :silence
43
- ActiveFedora::OmDatastream.deprecation_behavior = :silence
44
- ActiveFedora::NomDatastream.deprecation_behavior = :silence
45
- end
46
39
  # Stub out test stuff.
47
40
  config.before(:each) do
48
41
  begin
@@ -4,17 +4,20 @@ describe ActiveFedora::AttachedFiles do
4
4
  subject(:af_base) { ActiveFedora::Base.new }
5
5
  describe "has_subresource" do
6
6
  before do
7
- class Z < ActiveFedora::File
7
+ class Sample1 < ActiveFedora::File
8
+ end
9
+ class Sample2 < ActiveFedora::File
8
10
  end
9
11
  class FooHistory < ActiveFedora::Base
10
- has_subresource 'dsid', class_name: 'ActiveFedora::QualifiedDublinCoreDatastream'
11
- has_subresource 'complex_ds', autocreate: true, class_name: 'Z'
12
+ has_subresource 'dsid', class_name: 'Sample2'
13
+ has_subresource 'complex_ds', autocreate: true, class_name: 'Sample1'
12
14
  has_subresource 'thumbnail'
13
15
  has_subresource 'child_resource', class_name: 'ActiveFedora::Base'
14
16
  end
15
17
  end
16
18
  after do
17
- Object.send(:remove_const, :Z)
19
+ Object.send(:remove_const, :Sample1)
20
+ Object.send(:remove_const, :Sample2)
18
21
  Object.send(:remove_const, :FooHistory)
19
22
  end
20
23
 
@@ -26,12 +29,12 @@ describe ActiveFedora::AttachedFiles do
26
29
 
27
30
  it "lets you override defaults" do
28
31
  expect(FooHistory.child_resource_reflections[:complex_ds].options).to include(autocreate: true)
29
- expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq 'Z'
32
+ expect(FooHistory.child_resource_reflections[:complex_ds].class_name).to eq 'Sample1'
30
33
  end
31
34
 
32
35
  it "raises an error if you don't give a dsid" do
33
- expect { FooHistory.has_subresource nil, type: ActiveFedora::QualifiedDublinCoreDatastream }.to raise_error ArgumentError,
34
- "You must provide a path name (f.k.a. dsid) for the resource"
36
+ expect { FooHistory.has_subresource nil, type: Sample2 }.to raise_error ArgumentError,
37
+ "You must provide a path name (f.k.a. dsid) for the resource"
35
38
  end
36
39
  end
37
40
 
@@ -100,11 +100,13 @@ describe ActiveFedora::Base do
100
100
  class SpecialThing < ActiveFedora::Base
101
101
  end
102
102
  end
103
+
103
104
  after do
104
105
  Object.send(:remove_const, :SpecialThing)
105
106
  end
107
+
106
108
  it "records the decendants" do
107
- expect(described_class.descendants).to include(ModsArticle, SpecialThing)
109
+ expect(described_class.descendants).to include(SpecialThing)
108
110
  end
109
111
  end
110
112
 
@@ -32,19 +32,34 @@ describe ActiveFedora::Associations::HasManyAssociation do
32
32
  end
33
33
  end
34
34
 
35
- describe "Finding a polymorphic inverse relation" do
36
- before do
37
- # :books must come first, so that we can test that is being passed over in favor of :contents
38
- Page.has_many :books, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
39
- Page.has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
40
- end
35
+ describe "#find_polymorphic_inverse" do
41
36
  let(:book_reflection) { ActiveFedora::Reflection.create(:has_many, 'pages', nil, { predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf }, Book) }
42
37
  let(:association) { described_class.new(book, book_reflection) }
43
38
 
44
39
  subject(:af_page) { association.send(:find_polymorphic_inverse, page) }
45
40
 
46
- it "finds the HABTM reflection" do
47
- expect(af_page.name).to eq :contents
41
+ context "when a has_many is present" do
42
+ before do
43
+ # :books must come first, so that we can test that is being passed over in favor of :contents
44
+ Page.has_many :books, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
45
+ Page.has_and_belongs_to_many :contents, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
46
+ end
47
+
48
+ it "finds the HABTM reflection" do
49
+ expect(af_page.name).to eq :contents
50
+ end
51
+ end
52
+
53
+ context "when multiple belongs_to are present" do
54
+ before do
55
+ # :foo must come first, so that we can test that is being passed over in favor of :bar
56
+ Page.belongs_to :foo, predicate: ::RDF::Vocab::DC.isPartOf, class_name: 'ActiveFedora::Base'
57
+ Page.belongs_to :bar, predicate: ActiveFedora::RDF::Fcrepo::RelsExt.isPartOf, class_name: 'ActiveFedora::Base'
58
+ end
59
+
60
+ it "finds the belongs_to reflection" do
61
+ expect(af_page.name).to eq :bar
62
+ end
48
63
  end
49
64
  end
50
65
 
@@ -2,28 +2,32 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::Base do
4
4
  before do
5
- class MyDS < ActiveFedora::OmDatastream
5
+ class MyDS < ActiveFedora::File
6
6
  end
7
+
8
+ class MySample < ActiveFedora::File
9
+ end
10
+
7
11
  class Foo < ActiveFedora::Base
8
12
  has_subresource 'foostream', class_name: 'MyDS'
9
- has_subresource 'dcstream', class_name: 'ActiveFedora::QualifiedDublinCoreDatastream'
13
+ has_subresource 'dcstream', class_name: 'MySample'
10
14
  end
15
+
11
16
  class Bar < ActiveFedora::Base
12
17
  has_subresource 'barstream', class_name: 'MyDS'
13
18
  end
14
19
  end
20
+ let(:f) { Foo.new }
21
+ subject(:attached_files) { f.attached_files }
15
22
 
16
23
  it "doesn't overwrite stream specs" do
17
- f = Foo.new
18
- expect(f.attached_files.size).to eq 2
19
- streams = f.attached_files.values.map { |x| x.class.to_s }.sort
20
- expect(streams.pop).to eq "MyDS"
21
- expect(streams.pop).to eq "ActiveFedora::QualifiedDublinCoreDatastream"
24
+ expect(attached_files.values).to match_array [MyDS, MySample]
22
25
  end
23
26
 
24
27
  after do
25
28
  Object.send(:remove_const, :Bar)
26
29
  Object.send(:remove_const, :Foo)
27
30
  Object.send(:remove_const, :MyDS)
31
+ Object.send(:remove_const, :MySample)
28
32
  end
29
33
  end
@@ -15,7 +15,7 @@ describe ActiveFedora::ModelClassifier do
15
15
 
16
16
  describe ".class_from_string" do
17
17
  it "returns class constants based on strings" do
18
- expect(described_class.class_from_string("Om")).to eq Om
18
+ expect(described_class.class_from_string("String")).to eq String
19
19
  expect(described_class.class_from_string("ActiveFedora::RDF::IndexingService")).to eq ActiveFedora::RDF::IndexingService
20
20
  expect(described_class.class_from_string("IndexingService", ActiveFedora::RDF)).to eq ActiveFedora::RDF::IndexingService
21
21
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe ActiveFedora::RDF::IndexingService do
4
4
  before do
5
- class MyDatastream < ActiveFedora::NtriplesRDFDatastream
5
+ class MyObj < ActiveFedora::Base
6
6
  property :created, predicate: ::RDF::Vocab::DC.created
7
7
  property :title, predicate: ::RDF::Vocab::DC.title
8
8
  property :publisher, predicate: ::RDF::Vocab::DC.publisher
@@ -13,17 +13,17 @@ describe ActiveFedora::RDF::IndexingService do
13
13
  end
14
14
 
15
15
  after do
16
- Object.send(:remove_const, :MyDatastream)
16
+ Object.send(:remove_const, :MyObj)
17
17
  end
18
18
 
19
19
  let(:f2) do
20
- MyDatastream.new.tap do |obj|
21
- obj.created = Date.parse("2012-03-04")
22
- obj.title = "Of Mice and Men, The Sequel"
23
- obj.publisher = "Bob's Blogtastic Publishing"
20
+ MyObj.new.tap do |obj|
21
+ obj.created = [Date.parse("2012-03-04")]
22
+ obj.title = ["Of Mice and Men, The Sequel"]
23
+ obj.publisher = ["Bob's Blogtastic Publishing"]
24
24
  obj.based_near = ["Tacoma, WA", "Renton, WA"]
25
- obj.related_url = "http://example.org/blogtastic/"
26
- obj.rights = "Totally open, y'all"
25
+ obj.related_url = ["http://example.org/blogtastic/"]
26
+ obj.rights = ["Totally open, y'all"]
27
27
  end
28
28
  end
29
29
 
@@ -51,7 +51,7 @@ describe ActiveFedora::RDF::IndexingService do
51
51
  end
52
52
 
53
53
  before do
54
- allow(MyDatastream).to receive(:index_config).and_return(index_config)
54
+ allow(MyObj).to receive(:index_config).and_return(index_config)
55
55
  end
56
56
 
57
57
  let(:indexer) { described_class.new(f2) }
@@ -8,9 +8,7 @@ describe ActiveFedora do
8
8
  end
9
9
  end
10
10
 
11
- before(:each) do
12
- @test_object = ActiveFedora::Base.new
13
- end
11
+ subject(:test_object) { ActiveFedora::Base.new }
14
12
 
15
13
  describe ".id_field" do
16
14
  let(:field) { "MY_SAMPLE_ID".freeze }
@@ -19,9 +17,9 @@ describe ActiveFedora do
19
17
  end
20
18
 
21
19
  it "is used by ActiveFedora::Base.to_solr" do
22
- allow(@test_object).to receive(:id).and_return('changeme:123')
23
- expect(@test_object.to_solr[field.to_sym]).to eq 'changeme:123'
24
- expect(@test_object.to_solr[:id]).to be_nil
20
+ allow(test_object).to receive(:id).and_return('changeme:123')
21
+ expect(test_object.to_solr[field.to_sym]).to eq 'changeme:123'
22
+ expect(test_object.to_solr[:id]).to be_nil
25
23
  end
26
24
 
27
25
  it "is used by ActiveFedora::Base#search_with_conditions" do
@@ -43,17 +41,16 @@ describe ActiveFedora do
43
41
  end
44
42
 
45
43
  it "prevents Base.save from calling update_index if false" do
46
- dirty_ds = ActiveFedora::QualifiedDublinCoreDatastream.new
47
- @test_object.attached_files['ds1'] = dirty_ds
48
- allow(@test_object).to receive(:datastreams).and_return(ds1: dirty_ds)
49
- expect(@test_object).to receive(:update_index).never
50
- expect(@test_object).to receive(:refresh)
51
- @test_object.save
44
+ allow(test_object).to receive(:new_record?).and_return(false)
45
+ expect(test_object).to receive(:update_index).never
46
+ expect(test_object).to receive(:refresh)
47
+ test_object.save
52
48
  end
49
+
53
50
  it "prevents Base.delete from deleting the corresponding Solr document if false" do
54
- expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(@test_object.id).never
55
- expect(@test_object).to receive(:delete)
56
- @test_object.delete
51
+ expect(ActiveFedora::SolrService.instance.conn).to receive(:delete).with(test_object.id).never
52
+ expect(test_object).to receive(:delete)
53
+ test_object.delete
57
54
  end
58
55
  end
59
56
  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: 11.0.0.rc6
4
+ version: 11.0.0.rc7
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: 2016-08-12 00:00:00.000000000 Z
13
+ date: 2016-08-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rsolr
@@ -46,34 +46,6 @@ dependencies:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '3.4'
49
- - !ruby/object:Gem::Dependency
50
- name: om
51
- requirement: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - "~>"
54
- - !ruby/object:Gem::Version
55
- version: '3.1'
56
- type: :runtime
57
- prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - "~>"
61
- - !ruby/object:Gem::Version
62
- version: '3.1'
63
- - !ruby/object:Gem::Dependency
64
- name: nom-xml
65
- requirement: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 0.5.1
70
- type: :runtime
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 0.5.1
77
49
  - !ruby/object:Gem::Dependency
78
50
  name: activesupport
79
51
  requirement: !ruby/object:Gem::Requirement
@@ -128,20 +100,6 @@ dependencies:
128
100
  - - "~>"
129
101
  - !ruby/object:Gem::Version
130
102
  version: 0.10.0
131
- - !ruby/object:Gem::Dependency
132
- name: rdf-rdfxml
133
- requirement: !ruby/object:Gem::Requirement
134
- requirements:
135
- - - ">="
136
- - !ruby/object:Gem::Version
137
- version: '0'
138
- type: :runtime
139
- prerelease: false
140
- version_requirements: !ruby/object:Gem::Requirement
141
- requirements:
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: '0'
145
103
  - !ruby/object:Gem::Dependency
146
104
  name: deprecation
147
105
  requirement: !ruby/object:Gem::Requirement
@@ -445,8 +403,6 @@ files:
445
403
  - lib/active_fedora/core.rb
446
404
  - lib/active_fedora/core/fedora_id_translator.rb
447
405
  - lib/active_fedora/core/fedora_uri_translator.rb
448
- - lib/active_fedora/datastreams.rb
449
- - lib/active_fedora/datastreams/nokogiri_datastreams.rb
450
406
  - lib/active_fedora/default_model_mapper.rb
451
407
  - lib/active_fedora/delegated_attribute.rb
452
408
  - lib/active_fedora/errors.rb
@@ -480,9 +436,7 @@ files:
480
436
  - lib/active_fedora/log_subscriber.rb
481
437
  - lib/active_fedora/model_classifier.rb
482
438
  - lib/active_fedora/nested_attributes.rb
483
- - lib/active_fedora/nom_datastream.rb
484
439
  - lib/active_fedora/null_relation.rb
485
- - lib/active_fedora/om_datastream.rb
486
440
  - lib/active_fedora/orders.rb
487
441
  - lib/active_fedora/orders/collection_proxy.rb
488
442
  - lib/active_fedora/orders/list_node.rb
@@ -491,22 +445,17 @@ files:
491
445
  - lib/active_fedora/pathing.rb
492
446
  - lib/active_fedora/persistence.rb
493
447
  - lib/active_fedora/property.rb
494
- - lib/active_fedora/qualified_dublin_core_datastream.rb
495
448
  - lib/active_fedora/query_result_builder.rb
496
449
  - lib/active_fedora/querying.rb
497
450
  - lib/active_fedora/railtie.rb
498
451
  - lib/active_fedora/rake_support.rb
499
452
  - lib/active_fedora/rdf.rb
500
- - lib/active_fedora/rdf/datastream_indexing.rb
501
453
  - lib/active_fedora/rdf/fcrepo.rb
502
454
  - lib/active_fedora/rdf/field_map.rb
503
455
  - lib/active_fedora/rdf/field_map_entry.rb
504
456
  - lib/active_fedora/rdf/indexing_service.rb
505
- - lib/active_fedora/rdf/ntriples_rdf_datastream.rb
506
457
  - lib/active_fedora/rdf/persistence.rb
507
458
  - lib/active_fedora/rdf/project_hydra.rb
508
- - lib/active_fedora/rdf/rdf_datastream.rb
509
- - lib/active_fedora/rdf/rdfxml_datastream.rb
510
459
  - lib/active_fedora/reflection.rb
511
460
  - lib/active_fedora/relation.rb
512
461
  - lib/active_fedora/relation/calculations.rb
@@ -606,8 +555,6 @@ files:
606
555
  - spec/integration/caching_spec.rb
607
556
  - spec/integration/clean_connection_spec.rb
608
557
  - spec/integration/collection_association_spec.rb
609
- - spec/integration/complex_rdf_datastream_spec.rb
610
- - spec/integration/datastream_rdf_nested_attributes_spec.rb
611
558
  - spec/integration/date_time_properties_spec.rb
612
559
  - spec/integration/delete_all_spec.rb
613
560
  - spec/integration/direct_container_spec.rb
@@ -628,8 +575,6 @@ files:
628
575
  - spec/integration/marshal_spec.rb
629
576
  - spec/integration/nested_attribute_spec.rb
630
577
  - spec/integration/nested_hash_resources_spec.rb
631
- - spec/integration/ntriples_datastream_spec.rb
632
- - spec/integration/om_datastream_spec.rb
633
578
  - spec/integration/persistence_spec.rb
634
579
  - spec/integration/query_result_builder_spec.rb
635
580
  - spec/integration/rdf_nested_attributes_spec.rb
@@ -641,11 +586,8 @@ files:
641
586
  - spec/integration/versionable_spec.rb
642
587
  - spec/integration/with_metadata_spec.rb
643
588
  - spec/rcov.opts
644
- - spec/samples/hydra-mods_article_datastream.rb
645
- - spec/samples/models/mods_article.rb
646
589
  - spec/samples/oral_history_sample.xml
647
590
  - spec/samples/oral_history_xml.xml
648
- - spec/samples/samples.rb
649
591
  - spec/spec.opts
650
592
  - spec/spec_helper.rb
651
593
  - spec/support/an_active_model.rb
@@ -690,9 +632,6 @@ files:
690
632
  - spec/unit/loadable_from_json_spec.rb
691
633
  - spec/unit/logger_spec.rb
692
634
  - spec/unit/model_classifier_spec.rb
693
- - spec/unit/nom_datastream_spec.rb
694
- - spec/unit/ntriples_datastream_spec.rb
695
- - spec/unit/om_datastream_spec.rb
696
635
  - spec/unit/ordered_spec.rb
697
636
  - spec/unit/orders/list_node_spec.rb
698
637
  - spec/unit/orders/ordered_list_spec.rb
@@ -701,15 +640,11 @@ files:
701
640
  - spec/unit/persistence_spec.rb
702
641
  - spec/unit/property_predicate_spec.rb
703
642
  - spec/unit/property_spec.rb
704
- - spec/unit/qualified_dublin_core_datastream_spec.rb
705
643
  - spec/unit/query_result_builder_spec.rb
706
644
  - spec/unit/query_spec.rb
707
645
  - spec/unit/querying_spec.rb
708
646
  - spec/unit/rdf/indexing_service_spec.rb
709
- - spec/unit/rdf_datastream_spec.rb
710
- - spec/unit/rdf_resource_datastream_spec.rb
711
647
  - spec/unit/rdf_vocab_spec.rb
712
- - spec/unit/rdfxml_datastream_spec.rb
713
648
  - spec/unit/readonly_spec.rb
714
649
  - spec/unit/reflection_spec.rb
715
650
  - spec/unit/rspec_matchers/belong_to_associated_active_fedora_object_matcher_spec.rb
@@ -1,6 +0,0 @@
1
- module ActiveFedora
2
- module Datastreams
3
- extend ActiveSupport::Autoload
4
- autoload :NokogiriDatastreams, 'active_fedora/datastreams/nokogiri_datastreams'
5
- end
6
- end
@@ -1,119 +0,0 @@
1
- module ActiveFedora
2
- module Datastreams
3
- module NokogiriDatastreams
4
- extend ActiveSupport::Concern
5
-
6
- module ClassMethods
7
- def xml_template
8
- Nokogiri::XML::Document.parse("<xml/>")
9
- end
10
-
11
- def decorate_ng_xml(xml)
12
- xml
13
- end
14
- end
15
-
16
- def ng_xml
17
- @ng_xml ||= begin
18
- xml = if new_record?
19
- ## Load up the template
20
- self.class.xml_template
21
- else
22
- Nokogiri::XML::Document.parse(remote_content)
23
- end
24
- self.class.decorate_ng_xml xml
25
- end
26
- end
27
-
28
- def ng_xml=(new_xml)
29
- # before we set ng_xml, we load the datastream so we know if the new value differs.
30
- # TODO reinstate this
31
- # local_or_remote_content(true)
32
-
33
- case new_xml
34
- when Nokogiri::XML::Document
35
- self.content = new_xml.to_xml
36
- when Nokogiri::XML::Node
37
- ## Cast a fragment to a document
38
- self.content = new_xml.to_s
39
- when String
40
- self.content = new_xml
41
- else
42
- raise TypeError, "You passed a #{new_xml.class} into the ng_xml of the #{dsid} datastream. OmDatastream.ng_xml= only accepts Nokogiri::XML::Document, Nokogiri::XML::Element, Nokogiri::XML::Node, or raw XML (String) as inputs."
43
- end
44
- end
45
-
46
- def refresh_attributes
47
- changed_attributes.clear
48
- @ng_xml = nil
49
- end
50
-
51
- # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods
52
- def ng_xml_will_change!
53
- changed_attributes['ng_xml'] = nil
54
- end
55
-
56
- def ng_xml_doesnt_change!
57
- changed_attributes.delete('ng_xml')
58
- end
59
-
60
- # don't want content eagerly loaded by proxy, so implementing methods that would be implemented by define_attribute_methods
61
- def ng_xml_changed?
62
- changed_attributes.key? 'ng_xml'
63
- end
64
-
65
- def remote_content
66
- @ds_content ||= Nokogiri::XML(super).to_xml(&:no_declaration).strip
67
- end
68
-
69
- def content=(new_content)
70
- if remote_content != new_content.to_s
71
- ng_xml_will_change!
72
- @ng_xml = Nokogiri::XML::Document.parse(new_content)
73
- super(@ng_xml.to_s.strip)
74
- end
75
- self.class.decorate_ng_xml @ng_xml
76
- end
77
-
78
- def content_changed?
79
- return true if autocreate? && new_record?
80
- return false unless xml_loaded
81
- ng_xml_changed?
82
- end
83
-
84
- def to_xml(xml = nil)
85
- xml = ng_xml if xml.nil?
86
- ng_xml = self.ng_xml
87
- if ng_xml.respond_to?(:root) && ng_xml.root.nil? && self.class.respond_to?(:root_property_ref) && !self.class.root_property_ref.nil?
88
- ng_xml = self.class.generate(self.class.root_property_ref, "")
89
- xml = ng_xml if xml.root.nil?
90
- end
91
-
92
- unless xml == ng_xml || ng_xml.root.nil?
93
- if xml.is_a?(Nokogiri::XML::Document)
94
- xml.root.add_child(ng_xml.root)
95
- elsif xml.is_a?(Nokogiri::XML::Node)
96
- xml.add_child(ng_xml.root)
97
- else
98
- raise "You can only pass instances of Nokogiri::XML::Node into this method. You passed in #{xml}"
99
- end
100
- end
101
-
102
- xml.to_xml.strip
103
- end
104
-
105
- def content
106
- @content = to_xml if ng_xml_changed? || autocreate?
107
- super
108
- end
109
-
110
- def autocreate?
111
- changed_attributes.key? :profile
112
- end
113
-
114
- def xml_loaded
115
- instance_variable_defined? :@ng_xml
116
- end
117
- end
118
- end
119
- end