datacite-mapping 0.1.12 → 0.1.13

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: a9a277fd9f698e66af97ef9e5a6f961c552cb2ed
4
- data.tar.gz: 5c0d88b7e81d3bfdbb4693e43fc9b1d088333f9e
3
+ metadata.gz: a8781a8ea9333f3202323eab45df470e26e913e2
4
+ data.tar.gz: 59e9910f4613280d441f5e9ddddecc20d52ce96e
5
5
  SHA512:
6
- metadata.gz: 4a2d0acc09e211dffb9859bcf0071dd579ed6d8e3becb14dc32fa78df0009442e0da8977d6fd4d03b87ec76e883fab8cee98ae5f49d1b902412170b227e3a6d3
7
- data.tar.gz: bd715e764c2f815af6ccafeb82bedd6e85c6e8eaaf3d579539c6f8faac36df9ac703c51d13af9b0c303cd46605c58951cd85d7f7f171338988c53643687f0a85
6
+ metadata.gz: 0425ceacf4ca420bb2285a46e70d576b36fdc9021fe8db16143a5f97e75780624b5bb7a82ac3e1cc2f9b751e776e050ce20b24538779a82f08c406f3472308f5
7
+ data.tar.gz: 51cd66923ab219b649f099d1b2ca72ddbd07810eda31f156cf0729fd16ca5934e428a00292aa6ec673fe33f6d7cb2d1ebe71f64fbe66554d77f10d8cdc591793
data/CHANGES.md CHANGED
@@ -1,7 +1,17 @@
1
- ## 0.1.11 (28 April 2016)
1
+ ## 0.1.13 (2 May 2016)
2
+
3
+ - Update to XML::MappingExtensions 0.3.6 for improved namespace support
4
+ - Added `namespace_prefix` accessor to `Resource` to support explicit namespace prefixing
5
+ - Update to TypesafeEnum 0.1.7 for improved debug output
6
+
7
+ ## 0.1.12 (28 April 2016)
2
8
 
3
9
  - Update to XML::MappingExtensions 0.3.5
4
10
 
11
+ ## 0.1.11 (28 April 2016)
12
+
13
+ - (withdrawn)
14
+
5
15
  ## 0.1.10 (25 April 2016)
6
16
 
7
17
  - Replace all `require_relative` with absolute `require` to avoid symlink issues
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'typesafe_enum', '~> 0.1', '>= 0.1.5'
28
- spec.add_dependency 'xml-mapping_extensions', '~> 0.3', '>= 0.3.5'
27
+ spec.add_dependency 'typesafe_enum', '~> 0.1', '>= 0.1.7'
28
+ spec.add_dependency 'xml-mapping_extensions', '~> 0.3', '>= 0.3.6'
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 1.7'
31
31
  spec.add_development_dependency 'equivalent-xml', '~> 0.6.0'
@@ -4,7 +4,7 @@ module Datacite
4
4
  NAME = 'datacite-mapping'
5
5
 
6
6
  # The version of this gem
7
- VERSION = '0.1.12'
7
+ VERSION = '0.1.13'
8
8
 
9
9
  # The copyright notice for this gem
10
10
  COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'
@@ -1,4 +1,4 @@
1
- require 'xml/mapping'
1
+ require 'xml/mapping_extensions'
2
2
  require 'datacite/mapping/identifier'
3
3
  require 'datacite/mapping/creator'
4
4
  require 'datacite/mapping/title'
@@ -17,6 +17,11 @@ module Datacite
17
17
  class Resource
18
18
  include XML::Mapping
19
19
 
20
+ NAMESPACE = XML::MappingExtensions::Namespace.new(
21
+ uri: 'http://datacite.org/schema/kernel-3',
22
+ schema_location: 'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd'
23
+ )
24
+
20
25
  # Initialies a new {Resource}
21
26
  #
22
27
  # @param identifier [Identifier] a persistent identifier that identifies a resource.
@@ -39,6 +44,7 @@ module Datacite
39
44
  # @param descriptions [Array<Description>] all additional information that does not fit in any of the other categories.
40
45
  # @param geo_locations [Array<GeoLocations>] spatial region or named place where the data was gathered or about which the data is focused.
41
46
  def initialize(identifier:, creators:, titles:, publisher:, publication_year:, subjects: [], contributors: [], dates: [], language: 'en', resource_type: nil, alternate_identifiers: [], related_identifiers: [], sizes: [], formats: [], version: nil, rights_list: [], descriptions: [], geo_locations: []) # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists, Metrics/AbcSize
47
+ self.namespace = NAMESPACE
42
48
  self.identifier = identifier
43
49
  self.creators = creators
44
50
  self.titles = titles
@@ -59,6 +65,22 @@ module Datacite
59
65
  self.geo_locations = geo_locations
60
66
  end
61
67
 
68
+ # Overrides `Class.allocate`, used by `XML::Mapping` on read, to make sure
69
+ # the namespace gets set even when we don't call the initializer
70
+ def self.allocate
71
+ res = super
72
+ res.namespace = NAMESPACE
73
+ res
74
+ end
75
+
76
+ # Sets the namespace prefix to be used when writing out XML (defaults to nil)
77
+ # @param prefix [String, nil] The new prefix, or nil to use the default,
78
+ # unprefixed namespace
79
+ def namespace_prefix=(prefix)
80
+ old_namespace = namespace
81
+ self.namespace = ::XML::MappingExtensions::Namespace.new(uri: old_namespace.uri, schema_location: old_namespace.schema_location, prefix: prefix)
82
+ end
83
+
62
84
  def language
63
85
  @language || 'en'
64
86
  end
@@ -92,15 +114,15 @@ module Datacite
92
114
  @publication_year = value.to_i
93
115
  end
94
116
 
95
- # Overrides +::XML::Mapping.pre_save+ to write namespace information.
96
- # Used for writing.
97
- def pre_save(options = { mapping: :_default })
98
- xml = super(options)
99
- xml.add_namespace('http://datacite.org/schema/kernel-3')
100
- xml.add_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
101
- xml.add_attribute('xsi:schemaLocation', 'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd')
102
- xml
103
- end
117
+ # # Overrides +::XML::Mapping.pre_save+ to write namespace information.
118
+ # # Used for writing.
119
+ # def pre_save(options = { mapping: :_default })
120
+ # xml = super(options)
121
+ # xml.add_namespace('http://datacite.org/schema/kernel-3')
122
+ # xml.add_namespace('xsi', 'http://www.w3.org/2001/XMLSchema-instance')
123
+ # xml.add_attribute('xsi:schemaLocation', 'http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd')
124
+ # xml
125
+ # end
104
126
 
105
127
  # @!attribute [rw] identifier
106
128
  # @return [Identifier] a persistent identifier that identifies a resource.
@@ -769,6 +769,45 @@ module Datacite
769
769
  resource = Resource.parse_xml(xml_text)
770
770
  expect(resource.save_to_xml).to be_xml(xml_text)
771
771
  end
772
+
773
+ it 'allows a namespace prefix' do
774
+ resource = Resource.new(
775
+ identifier: @id,
776
+ creators: @creators,
777
+ titles: @titles,
778
+ publisher: @publisher,
779
+ publication_year: @pub_year
780
+ )
781
+ resource.namespace_prefix = 'dcs'
782
+ expect(resource.namespace.prefix).to eq('dcs')
783
+
784
+ expected = '<dcs:resource xmlns:dcs="http://datacite.org/schema/kernel-3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd">
785
+ <dcs:identifier identifierType="DOI">10.14749/1407399495</dcs:identifier>
786
+ <dcs:creators>
787
+ <dcs:creator>
788
+ <dcs:creatorName>Hedy Lamarr</dcs:creatorName>
789
+ <dcs:nameIdentifier nameIdentifierScheme="ISNI" schemeURI="http://isni.org/">0000-0001-1690-159X</dcs:nameIdentifier>
790
+ <dcs:affiliation>United Artists</dcs:affiliation>
791
+ <dcs:affiliation>Metro-Goldwyn-Mayer</dcs:affiliation>
792
+ </dcs:creator>
793
+ <dcs:creator>
794
+ <dcs:creatorName>Herschlag, Natalie</dcs:creatorName>
795
+ <dcs:nameIdentifier nameIdentifierScheme="ISNI" schemeURI="http://isni.org/">0000-0001-0907-8419</dcs:nameIdentifier>
796
+ <dcs:affiliation>Gaumont Buena Vista International</dcs:affiliation>
797
+ <dcs:affiliation>20th Century Fox</dcs:affiliation>
798
+ </dcs:creator>
799
+ </dcs:creators>
800
+ <dcs:titles>
801
+ <dcs:title xml:lang="en-emodeng">An Account of a Very Odd Monstrous Calf</dcs:title>
802
+ <dcs:title xml:lang="en-emodeng" titleType="Subtitle">And a Contest between Two Artists about Optick Glasses, &amp;c</dcs:title>
803
+ </dcs:titles>
804
+ <dcs:publisher>California Digital Library</dcs:publisher>
805
+ <dcs:publicationYear>2015</dcs:publicationYear>
806
+ <dcs:language>en</dcs:language>
807
+ </dcs:resource>'
808
+
809
+ expect(resource.save_to_xml).to be_xml(expected)
810
+ end
772
811
  end
773
812
 
774
813
  describe 'convenience accessors' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datacite-mapping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Moles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-28 00:00:00.000000000 Z
11
+ date: 2016-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typesafe_enum
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '0.1'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.1.5
22
+ version: 0.1.7
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '0.1'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.1.5
32
+ version: 0.1.7
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: xml-mapping_extensions
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '0.3'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 0.3.5
42
+ version: 0.3.6
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: '0.3'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 0.3.5
52
+ version: 0.3.6
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: bundler
55
55
  requirement: !ruby/object:Gem::Requirement