ddr-models 3.0.0.alpha.2 → 3.0.0.alpha.3

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/.travis.yml +5 -2
  3. data/lib/ddr/actions/fixity_check.rb +8 -5
  4. data/lib/ddr/auth/ability_definitions/role_based_ability_definitions.rb +1 -1
  5. data/lib/ddr/auth/grouper_gateway.rb +51 -53
  6. data/lib/ddr/datastreams/datastream_behavior.rb +65 -66
  7. data/lib/ddr/events/event.rb +2 -2
  8. data/lib/ddr/events/fixity_check_event.rb +3 -2
  9. data/lib/ddr/index/fields.rb +1 -0
  10. data/lib/ddr/managers/derivatives_manager.rb +3 -3
  11. data/lib/ddr/managers/permanent_id_manager.rb +2 -2
  12. data/lib/ddr/models.rb +5 -2
  13. data/lib/ddr/models/attached_file_profile.rb +12 -0
  14. data/lib/ddr/models/attached_files_profile.rb +21 -0
  15. data/lib/ddr/models/base.rb +77 -74
  16. data/lib/ddr/models/describable.rb +3 -3
  17. data/lib/ddr/models/governable.rb +1 -1
  18. data/lib/ddr/models/indexing.rb +1 -0
  19. data/lib/ddr/models/licenses/license.rb +8 -2
  20. data/lib/ddr/models/metadata/descriptive_metadata.rb +6 -10
  21. data/lib/ddr/models/metadata/metadata_mapping.rb +45 -0
  22. data/lib/ddr/models/object_api.rb +11 -0
  23. data/lib/ddr/models/solr_document.rb +16 -9
  24. data/lib/ddr/models/url_safe_id.rb +9 -0
  25. data/lib/ddr/models/version.rb +1 -1
  26. data/lib/ddr/utils.rb +3 -3
  27. data/spec/auth/ability_spec.rb +9 -9
  28. data/spec/jobs/fits_file_characterization_spec.rb +3 -3
  29. data/spec/models/active_fedora_base_spec.rb +4 -4
  30. data/spec/models/active_fedora_datastream_spec.rb +6 -8
  31. data/spec/models/collection_spec.rb +1 -1
  32. data/spec/models/descriptive_metadata_spec.rb +0 -3
  33. data/spec/models/effective_license_spec.rb +4 -4
  34. data/spec/models/indexing_spec.rb +1 -1
  35. data/spec/models/license_spec.rb +3 -3
  36. data/spec/spec_helper.rb +6 -5
  37. data/spec/support/shared_examples_for_ddr_models.rb +1 -0
  38. data/spec/support/shared_examples_for_describables.rb +2 -2
  39. data/spec/support/shared_examples_for_events.rb +6 -6
  40. data/spec/support/shared_examples_for_fixity_checkable_spec.rb +15 -0
  41. data/spec/support/shared_examples_for_governables.rb +1 -1
  42. metadata +9 -4
  43. data/lib/ddr/models/metadata/metadata_mapper.rb +0 -32
  44. data/lib/ddr/models/metadata/metadata_mappers.rb +0 -18
@@ -21,11 +21,11 @@ module Ddr::Auth
21
21
  describe "\"#{dsid}\"" do
22
22
  let(:ds) { obj.datastreams[dsid] }
23
23
  describe "can #{permission.inspect} object" do
24
- before { subject.can permission, obj.pid }
24
+ before { subject.can permission, obj.id }
25
25
  it { should be_able_to(:download, ds) }
26
26
  end
27
27
  describe "cannot #{permission.inspect} object" do
28
- before { subject.cannot permission, obj.pid }
28
+ before { subject.cannot permission, obj.id }
29
29
  it { should_not be_able_to(:download, ds) }
30
30
  end
31
31
  end
@@ -35,7 +35,7 @@ module Ddr::Auth
35
35
  (Component.ds_specs.keys.map(&:to_s) - DatastreamAbilityDefinitions::DATASTREAM_DOWNLOAD_ABILITIES.keys).each do |dsid|
36
36
  describe "\"#{dsid}\"" do
37
37
  let(:ds) { obj.datastreams[dsid] }
38
- before { subject.can :download, obj.pid }
38
+ before { subject.can :download, obj.id }
39
39
  it { should_not be_able_to(:download, ds) }
40
40
  end
41
41
  end
@@ -175,23 +175,23 @@ module Ddr::Auth
175
175
  end
176
176
 
177
177
  describe "with a Ddr model instance" do
178
- let(:obj) { Collection.new(pid: "test:1") }
179
- let(:cache_key) { obj.pid }
178
+ let(:obj) { Collection.new(id: "test-1") }
179
+ let(:cache_key) { obj.id }
180
180
  let(:perm_obj) { obj }
181
181
  it_behaves_like "it has role based abilities"
182
182
  end
183
183
 
184
184
  describe "with a Solr document" do
185
- let(:obj) { SolrDocument.new({"id"=>"test:1"}) }
186
- let(:cache_key) { obj.pid }
185
+ let(:obj) { SolrDocument.new({"id"=>"test-1"}) }
186
+ let(:cache_key) { obj.id }
187
187
  let(:perm_obj) { obj }
188
188
  it_behaves_like "it has role based abilities"
189
189
  end
190
190
 
191
191
  describe "with a String" do
192
- let(:obj) { "test:1" }
192
+ let(:obj) { "test-1" }
193
193
  let(:cache_key) { obj }
194
- let(:perm_obj) { SolrDocument.new({"id"=>"test:1"}) }
194
+ let(:perm_obj) { SolrDocument.new({"id"=>"test-1"}) }
195
195
  before do
196
196
  allow_any_instance_of(RoleBasedAbilityDefinitions).to receive(:permissions_doc).with(obj) { perm_obj }
197
197
  end
@@ -24,7 +24,7 @@ module Ddr::Jobs
24
24
  before do
25
25
  allow(Open3).to receive(:capture3) { [ stdout_msg, stderr_msg, $? ] }
26
26
  allow_any_instance_of(Process::Status).to receive(:success?) { true }
27
- Ddr::Jobs::FitsFileCharacterization.perform(object.pid)
27
+ Ddr::Jobs::FitsFileCharacterization.perform(object.id)
28
28
  object.reload
29
29
  end
30
30
  it "should populate the fits datastream" do
@@ -38,7 +38,7 @@ module Ddr::Jobs
38
38
  before do
39
39
  allow(Open3).to receive(:capture3) { [ stdout_msg, stderr_msg, $? ] }
40
40
  allow_any_instance_of(Process::Status).to receive(:success?) { false }
41
- Ddr::Jobs::FitsFileCharacterization.perform(object.pid)
41
+ Ddr::Jobs::FitsFileCharacterization.perform(object.id)
42
42
  object.reload
43
43
  end
44
44
  it "should not populate the fits datastream" do
@@ -49,4 +49,4 @@ module Ddr::Jobs
49
49
  end
50
50
 
51
51
  end
52
- end
52
+ end
@@ -6,22 +6,22 @@ RSpec.describe ActiveFedora::Base do
6
6
  let!(:collection) { FactoryGirl.create(:collection) }
7
7
  describe "when called on the wrong class" do
8
8
  it "should raise an exception" do
9
- expect { Item.find(collection.pid) }.to raise_error(ActiveFedora::ActiveFedoraError)
9
+ expect { Item.find(collection.id) }.to raise_error(ActiveFedora::ActiveFedoraError)
10
10
  end
11
11
  end
12
12
  describe "when called on Ddr::Models::Base" do
13
13
  it "should cast to the object's class" do
14
- expect(Ddr::Models::Base.find(collection.pid)).to eq(collection)
14
+ expect(Ddr::Models::Base.find(collection.id)).to eq(collection)
15
15
  end
16
16
  end
17
17
  describe "when called on ActiveFedora::Base" do
18
18
  it "should cast to the object's class" do
19
- expect(ActiveFedora::Base.find(collection.pid)).to eq(collection)
19
+ expect(ActiveFedora::Base.find(collection.id)).to eq(collection)
20
20
  end
21
21
  end
22
22
  describe "when called on the object's class" do
23
23
  it "should return the object" do
24
- expect(Collection.find(collection.pid)).to eq(collection)
24
+ expect(Collection.find(collection.id)).to eq(collection)
25
25
  end
26
26
  end
27
27
  end
@@ -65,20 +65,20 @@ module ActiveFedora
65
65
  context "the datstream is new" do
66
66
  before { allow(subject).to receive(:new_record?) { true } }
67
67
  it "should raise an exception" do
68
- expect { subject.validate_checksum!(checksum, checksum_type) }.to raise_error
68
+ expect { subject.validate_checksum!("bb3200c2ddaee4bd7b9a4dc1ad3e10ed886eaef1") }.to raise_error(Ddr::Models::Error)
69
69
  end
70
70
  end
71
71
  context "the datastream content has changed" do
72
72
  before { allow(subject).to receive(:content_changed?) { true } }
73
73
  it "should raise an exception" do
74
- expect { subject.validate_checksum!(checksum, checksum_type) }.to raise_error
74
+ expect { subject.validate_checksum!("bb3200c2ddaee4bd7b9a4dc1ad3e10ed886eaef1") }.to raise_error(Ddr::Models::Error)
75
75
  end
76
76
  end
77
77
  end
78
78
  context "with persisted content" do
79
79
  before do
80
80
  allow(subject).to receive(:new_record?) { false }
81
- allow(subject).to receive(:pid) { "foobar:1" }
81
+ allow(subject).to receive(:pid) { "foobar-1" }
82
82
  allow(subject).to receive(:checksum) { checksum }
83
83
  end
84
84
  context "and the repository internal checksum in invalid" do
@@ -99,21 +99,19 @@ module ActiveFedora
99
99
  end
100
100
  context "and the checksum type is nil" do
101
101
  it "should compare the provided checksum with the datastream checksum" do
102
- expect { subject.validate_checksum!(checksum.value) }
103
- .not_to raise_error(Ddr::Models::Error)
102
+ expect { subject.validate_checksum!(checksum.value) }.not_to raise_error
104
103
  end
105
104
  end
106
105
  context "and the checksum type is the same as the datastream checksum type" do
107
106
  it "should compare the provided checksum with the datastream checksum" do
108
- expect { subject.validate_checksum!(checksum.value, checksum.algorithm) }
109
- .not_to raise_error(Ddr::Models::Error)
107
+ expect { subject.validate_checksum!(checksum.value, checksum.algorithm) }.not_to raise_error
110
108
  end
111
109
  end
112
110
  context "and the checksum type differs from the datastream checksum type" do
113
111
  let!(:md5digest) { "273ae0f4aa60d94e89bc0e0652ae2c8f" }
114
112
  it "should generate a checksum for comparison" do
115
113
  allow(subject).to receive(:content_digest).with("MD5") { md5digest }
116
- expect { subject.validate_checksum!(md5digest, "MD5") }.not_to raise_error(Ddr::Models::Error)
114
+ expect { subject.validate_checksum!(md5digest, "MD5") }.not_to raise_error
117
115
  end
118
116
  end
119
117
  context "and the checksum doesn't match" do
@@ -13,7 +13,7 @@ RSpec.describe Collection, type: :model do
13
13
  component = Component.create
14
14
  docs = subject.components_from_solr
15
15
  expect(docs.size).to eq(1)
16
- expect(docs.first.id).to eq(component.pid)
16
+ expect(docs.first.id).to eq(component.id)
17
17
  end
18
18
  end
19
19
 
@@ -1,7 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'rdf/isomorphic'
3
-
4
- include RDF::Isomorphic
5
2
 
6
3
  module Ddr::Models
7
4
  RSpec.describe DescriptiveMetadata do
@@ -8,7 +8,7 @@ module Ddr::Models
8
8
  let(:license) { License.new(url: url) }
9
9
  before { allow(License).to receive(:find).with(url: url) { license } }
10
10
 
11
- let(:obj) { double(pid: "test:1", id: "test:1", license: nil, parent: nil, admin_policy: nil, admin_policy_id: nil) }
11
+ let(:obj) { double(id: "test-1", license: nil, parent: nil, admin_policy: nil, admin_policy_id: nil) }
12
12
 
13
13
  describe "when the object has a license" do
14
14
  before { allow(obj).to receive(:license) { url } }
@@ -17,7 +17,7 @@ module Ddr::Models
17
17
 
18
18
  describe "when the object does not have a license" do
19
19
  describe "and the object has a parent" do
20
- let(:parent) { double(pid: "test:2", license: nil) }
20
+ let(:parent) { double(id: "test-2", license: nil) }
21
21
  before do
22
22
  allow(obj).to receive(:parent) { parent }
23
23
  end
@@ -33,11 +33,11 @@ module Ddr::Models
33
33
  end
34
34
  describe "and the object does not have a parent" do
35
35
  describe "and the object has an admin policy" do
36
- let(:admin_policy) { double(pid: "test:3", id: "test:3", license: nil) }
36
+ let(:admin_policy) { double(id: "test-3", license: nil) }
37
37
  before { allow(obj).to receive(:admin_policy) { admin_policy } }
38
38
  describe "and the admin policy has a different id from the object" do
39
39
  before do
40
- allow(obj).to receive(:admin_policy_id) { "test:3" }
40
+ allow(obj).to receive(:admin_policy_id) { "test-3" }
41
41
  end
42
42
  describe "and the admin policy has a license" do
43
43
  before do
@@ -1,7 +1,7 @@
1
1
  module Ddr::Models
2
2
  RSpec.describe Indexing do
3
3
 
4
- let(:obj) { FactoryGirl.build(:item) }
4
+ let(:obj) { FactoryGirl.create(:item) }
5
5
 
6
6
  let(:role1) { FactoryGirl.build(:role, :curator, :person, :resource) }
7
7
  let(:role2) { FactoryGirl.build(:role, :curator, :person, :policy) }
@@ -6,16 +6,16 @@ module Ddr::Models
6
6
 
7
7
  describe "when the object has a license URL" do
8
8
  let(:url) { "http://example.com" }
9
- let(:obj) { double(pid: "test:1", license: url) }
9
+ let(:obj) { double(id: "test-1", license: url) }
10
10
  before do
11
11
  allow(described_class).to receive(:find).with(url: url) { described_class.new(url: url, title: "A License") }
12
12
  end
13
- its(:pid) { is_expected.to eq("test:1") }
13
+ its(:pid) { is_expected.to eq("test-1") }
14
14
  its(:to_s) { is_expected.to eq("A License") }
15
15
  end
16
16
 
17
17
  describe "when the object does not have a license" do
18
- let(:obj) { double(pid: "test:1", license: nil) }
18
+ let(:obj) { double(id: "test-1", license: nil) }
19
19
  it { is_expected.to be_nil }
20
20
  end
21
21
  end
@@ -9,22 +9,23 @@ require "rails"
9
9
  require "rspec/rails"
10
10
  require "rspec/its"
11
11
  require "factory_girl_rails"
12
- require "database_cleaner"
13
12
  require "tempfile"
14
- require "resque"
15
13
  require "cancan/matchers"
16
14
  require 'equivalent-xml/rspec_matchers'
15
+ require 'active_fedora/cleaner'
17
16
 
17
+ require "resque"
18
18
  Resque.inline = true
19
19
 
20
20
  OmniAuth.config.test_mode = true
21
21
 
22
22
  Dir[File.join(File.dirname(__FILE__), "support", "*.rb")].each { |f| require f }
23
23
 
24
+ require "database_cleaner"
24
25
  DatabaseCleaner.strategy = :truncation
25
26
 
26
27
  # Silence deprecation warnings
27
- warn "Default deprecation behavior set to :silence!"
28
+ warn "WARNING: Default deprecation behavior set to :silence!"
28
29
  Deprecation.default_deprecation_behavior = :silence
29
30
 
30
31
  RSpec.configure do |config|
@@ -105,7 +106,7 @@ RSpec.configure do |config|
105
106
 
106
107
  config.before(:suite) do
107
108
  DatabaseCleaner.clean
108
- ActiveFedora::Base.destroy_all
109
+ ActiveFedora::Cleaner.clean!
109
110
  Ddr::Derivatives.configure do |config|
110
111
  config.update_derivatives = [ :multires_image, :thumbnail ]
111
112
  end
@@ -127,7 +128,7 @@ RSpec.configure do |config|
127
128
  end
128
129
 
129
130
  config.after(:each) do
130
- ActiveFedora::Base.destroy_all
131
+ ActiveFedora::Cleaner.clean!
131
132
  end
132
133
 
133
134
  end
@@ -4,6 +4,7 @@ RSpec.shared_examples "a DDR model" do
4
4
  it_behaves_like "a governable object"
5
5
  it_behaves_like "an object that has a display title"
6
6
  it_behaves_like "an object that has identifiers"
7
+ it_behaves_like "a fixity checkable object"
7
8
 
8
9
  describe "events" do
9
10
  describe "on deletion with #destroy" do
@@ -19,9 +19,9 @@ RSpec.shared_examples "a describable object" do
19
19
  describe "arguments" do
20
20
  it "with fixed results" do
21
21
  expect(object.desc_metadata_terms(:dcterms))
22
- .to eq(Ddr::Models::MetadataMapper.dc11.unqualified_names + (Ddr::Models::MetadataMapper.dcterms.unqualified_names - Ddr::Models::MetadataMapper.dc11.unqualified_names))
22
+ .to eq(Ddr::Models::MetadataMapping.dc11.unqualified_names + (Ddr::Models::MetadataMapping.dcterms.unqualified_names - Ddr::Models::MetadataMapping.dc11.unqualified_names))
23
23
  expect(object.desc_metadata_terms(:dcterms))
24
- .to match_array(Ddr::Models::MetadataMapper.dcterms.unqualified_names)
24
+ .to match_array(Ddr::Models::MetadataMapping.dcterms.unqualified_names)
25
25
  expect(object.desc_metadata_terms(:duke)).to eq Ddr::Vocab::Vocabulary.term_names(Ddr::Vocab::DukeTerms)
26
26
  expect(object.desc_metadata_terms(:dcterms_elements11)).to eq Ddr::Vocab::Vocabulary.term_names(RDF::DC11)
27
27
  expect(object.desc_metadata_terms(:defined_attributes)).to match_array Ddr::Vocab::Vocabulary.term_names(RDF::DC11)
@@ -82,7 +82,7 @@ RSpec.shared_examples "an event" do
82
82
  end
83
83
  context "when attributes are set" do
84
84
  let(:obj) { ActiveFedora::Base.create }
85
- let(:event) { described_class.new(pid: obj.pid, outcome: Ddr::Events::Event::FAILURE, event_date_time: Time.utc(2013), software: "Test", summary: "A terrible disaster") }
85
+ let(:event) { described_class.new(pid: obj.id, outcome: Ddr::Events::Event::FAILURE, event_date_time: Time.utc(2013), software: "Test", summary: "A terrible disaster") }
86
86
  it "should not overwrite attributes" do
87
87
  expect { event.send(:set_defaults) }.not_to change { event.outcome }
88
88
  expect { event.send(:set_defaults) }.not_to change { event.event_date_time }
@@ -93,25 +93,25 @@ RSpec.shared_examples "an event" do
93
93
  end
94
94
 
95
95
  describe "object getter" do
96
- subject { described_class.new(pid: "test:123") }
96
+ subject { described_class.new(pid: "test-123") }
97
97
  let(:object) { mock_object }
98
- before { allow(ActiveFedora::Base).to receive(:find).with("test:123") { object } }
98
+ before { allow(ActiveFedora::Base).to receive(:find).with("test-123") { object } }
99
99
  it "should retrieve the object" do
100
100
  expect(subject.object).to eq object
101
101
  end
102
102
  it "should cache the object" do
103
- expect(ActiveFedora::Base).to receive(:find).with("test:123").once
103
+ expect(ActiveFedora::Base).to receive(:find).with("test-123").once
104
104
  subject.object
105
105
  subject.object
106
106
  end
107
107
  end
108
108
 
109
109
  describe "object setter" do
110
- let(:object) { mock_object(pid: "test:123") }
110
+ let(:object) { mock_object(id: "test-123") }
111
111
  it "should set the event pid and object" do
112
112
  allow(object).to receive(:new_record?) { false }
113
113
  subject.object = object
114
- expect(subject.pid).to eq "test:123"
114
+ expect(subject.pid).to eq "test-123"
115
115
  expect(subject.object).to eq object
116
116
  end
117
117
  it "should raise an ArgumentError if object is a new record" do
@@ -0,0 +1,15 @@
1
+ RSpec.shared_examples "a fixity checkable object" do
2
+
3
+ let(:object) { described_class.new }
4
+
5
+ describe "fixity check" do
6
+ before do
7
+ object.thumbnail.content = '1234567890'
8
+ object.save(validate: false)
9
+ end
10
+ it "should be able to perform a fixity check" do
11
+ expect(Ddr::Actions::FixityCheck.execute(object)).to_not be_nil
12
+ end
13
+ end
14
+
15
+ end
@@ -11,7 +11,7 @@ RSpec.shared_examples "a governable object" do
11
11
  it "should set its admin policy with #admin_policy= and get with #admin_policy" do
12
12
  object.admin_policy = coll
13
13
  object.save(validate: false)
14
- expect(ActiveFedora::Base.find(object.pid).admin_policy).to eq(coll)
14
+ expect(ActiveFedora::Base.find(object.id).admin_policy).to eq(coll)
15
15
  end
16
16
  end
17
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddr-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.alpha.2
4
+ version: 3.0.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Coble
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-23 00:00:00.000000000 Z
12
+ date: 2015-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -494,6 +494,8 @@ files:
494
494
  - lib/ddr/models.rb
495
495
  - lib/ddr/models/access_controllable.rb
496
496
  - lib/ddr/models/admin_set.rb
497
+ - lib/ddr/models/attached_file_profile.rb
498
+ - lib/ddr/models/attached_files_profile.rb
497
499
  - lib/ddr/models/base.rb
498
500
  - lib/ddr/models/describable.rb
499
501
  - lib/ddr/models/engine.rb
@@ -518,14 +520,15 @@ files:
518
520
  - lib/ddr/models/licenses/parent_license.rb
519
521
  - lib/ddr/models/metadata/descriptive_metadata.rb
520
522
  - lib/ddr/models/metadata/metadata.rb
521
- - lib/ddr/models/metadata/metadata_mapper.rb
522
- - lib/ddr/models/metadata/metadata_mappers.rb
523
+ - lib/ddr/models/metadata/metadata_mapping.rb
523
524
  - lib/ddr/models/metadata/metadata_term.rb
524
525
  - lib/ddr/models/metadata/metadata_vocabularies.rb
525
526
  - lib/ddr/models/metadata/metadata_vocabulary.rb
527
+ - lib/ddr/models/object_api.rb
526
528
  - lib/ddr/models/solr_document.rb
527
529
  - lib/ddr/models/struct_div.rb
528
530
  - lib/ddr/models/structure.rb
531
+ - lib/ddr/models/url_safe_id.rb
529
532
  - lib/ddr/models/version.rb
530
533
  - lib/ddr/models/year_facet.rb
531
534
  - lib/ddr/notifications.rb
@@ -669,6 +672,7 @@ files:
669
672
  - spec/support/shared_examples_for_ddr_models.rb
670
673
  - spec/support/shared_examples_for_describables.rb
671
674
  - spec/support/shared_examples_for_events.rb
675
+ - spec/support/shared_examples_for_fixity_checkable_spec.rb
672
676
  - spec/support/shared_examples_for_governables.rb
673
677
  - spec/support/shared_examples_for_has_content.rb
674
678
  - spec/support/shared_examples_for_indexing.rb
@@ -832,6 +836,7 @@ test_files:
832
836
  - spec/support/shared_examples_for_ddr_models.rb
833
837
  - spec/support/shared_examples_for_describables.rb
834
838
  - spec/support/shared_examples_for_events.rb
839
+ - spec/support/shared_examples_for_fixity_checkable_spec.rb
835
840
  - spec/support/shared_examples_for_governables.rb
836
841
  - spec/support/shared_examples_for_has_content.rb
837
842
  - spec/support/shared_examples_for_indexing.rb
@@ -1,32 +0,0 @@
1
- module Ddr::Models
2
- #
3
- # Maps vocabulary terms to names
4
- #
5
- class MetadataMapper
6
- extend MetadataMappers
7
-
8
- attr_reader :mapping
9
-
10
- # param vocab [MetadataVocabulary] the vocabulary
11
- def initialize(vocab)
12
- @mapping = vocab.terms.each_with_object({}) do |term, memo|
13
- memo[term.qualified_name] = term
14
- end
15
- end
16
-
17
- def terms
18
- mapping.values
19
- end
20
-
21
- def unqualified_names
22
- mapping.values.map(&:unqualified_name)
23
- end
24
-
25
- def merge(other)
26
- merged = self.dup
27
- merged.mapping.merge! other.mapping
28
- merged
29
- end
30
-
31
- end
32
- end