stash-wrapper 0.1.11.1 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +89 -10
  3. data/.rakeTasks +7 -0
  4. data/.rubocop.yml +6 -20
  5. data/.ruby-version +1 -1
  6. data/CHANGES.md +8 -0
  7. data/LICENSE.md +1 -1
  8. data/README.md +2 -2
  9. data/Rakefile +2 -2
  10. data/example.rb +2 -1
  11. data/lib/stash/wrapper.rb +2 -2
  12. data/lib/stash/wrapper/descriptive_node.rb +2 -2
  13. data/lib/stash/wrapper/embargo.rb +23 -13
  14. data/lib/stash/wrapper/embargo_type.rb +1 -1
  15. data/lib/stash/wrapper/identifier.rb +6 -2
  16. data/lib/stash/wrapper/identifier_type.rb +5 -0
  17. data/lib/stash/wrapper/inventory.rb +2 -2
  18. data/lib/stash/wrapper/license.rb +2 -2
  19. data/lib/stash/wrapper/module_info.rb +4 -4
  20. data/lib/stash/wrapper/size.rb +8 -2
  21. data/lib/stash/wrapper/stash_administrative.rb +30 -10
  22. data/lib/stash/wrapper/stash_wrapper.rb +8 -4
  23. data/lib/stash/wrapper/version.rb +15 -4
  24. data/spec/.rubocop.yml +1 -4
  25. data/spec/data/wrapper/mrtoai-wrapper-old-schema-location.xml +73 -0
  26. data/spec/data/wrapper/mrtoai-wrapper.xml +33 -33
  27. data/spec/data/wrapper/stash_wrapper.xsd +2 -2
  28. data/spec/data/wrapper/wrapper-1.xml +4 -7
  29. data/spec/data/wrapper/wrapper-2.xml +2 -2
  30. data/spec/rspec_custom_matchers.rb +61 -38
  31. data/spec/unit/stash/wrapper/identifier_spec.rb +22 -0
  32. data/spec/unit/stash/wrapper/inventory_spec.rb +1 -1
  33. data/spec/unit/stash/wrapper/stash_administrative_spec.rb +68 -26
  34. data/spec/unit/stash/wrapper/stash_wrapper_spec.rb +57 -37
  35. data/spec/unit/stash/wrapper/version_spec.rb +9 -0
  36. data/stash-wrapper.gemspec +35 -29
  37. metadata +76 -27
  38. data/data/kernel3_to_oaidc.xsl +0 -220
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d5f8980de3819d980d8e5dd98008f886be978be5
4
- data.tar.gz: e75bc9674c28df79152d0cb804cfa5befab17d65
2
+ SHA256:
3
+ metadata.gz: 8c2df6f3332aaa9d993dfda573f17d9127ac1e902c1f8705ea65a8ba72864208
4
+ data.tar.gz: 6cf310390b1a80e396e51a12de63107142881c6059731f812030919399eca940
5
5
  SHA512:
6
- metadata.gz: 8e491506be906942e7f76340db12dfae27f5766cf0381ed5bd0927e05df9ca723a57e566a7b78001d0c3a3ac07c02d59a4503c24f4627efce23f4da3c3d95463
7
- data.tar.gz: d14a974affa84689ab014e8492dbe8d7234557b78394d36d68d67cba876baec9ef51230f61db0b4357c19977ac38bfe2a9e051ef9fddc13f1215d3b773eecde1
6
+ metadata.gz: 915f637e7a4940cd413f852b951c83ef9a3628fec9f39c9a0eaf1f6254ca481bde66bb53c1cdc3282d5885744b4400f1568886748f4191fdf80ca1483aeff25b
7
+ data.tar.gz: 8f37b259d343d835cfd684852430160b029911a8a8ba8565d316575cdfe1345625cc709377b5e25fce21a21e659896b5de0eb13dc2a73aae23ae840032024e15
data/.gitignore CHANGED
@@ -27,20 +27,99 @@ db/*.sqlite3
27
27
 
28
28
  /log/
29
29
 
30
- # IntelliJ
30
+ # Mac OS
31
+
32
+ .DS_Store
33
+ #### joe made this: http://goel.io/joe
34
+
35
+ #####=== JetBrains ===#####
36
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
37
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
38
+
39
+ # User-specific stuff:
40
+ .idea/workspace.xml
41
+ .idea/tasks.xml
42
+
43
+ # Sensitive or high-churn files:
44
+ .idea/dataSources/
45
+ .idea/dataSources.ids
46
+ .idea/dataSources.xml
47
+ .idea/dataSources.local.xml
48
+ .idea/sqlDataSources.xml
49
+ .idea/dynamic.xml
50
+ .idea/uiDesigner.xml
31
51
 
32
- *.iml
33
- *.ipr
52
+ # Gradle:
53
+ .idea/gradle.xml
54
+ .idea/libraries
55
+
56
+ # Mongo Explorer plugin:
57
+ .idea/mongoSettings.xml
58
+
59
+ ## File-based project format:
34
60
  *.iws
35
- *.ids
36
- .rakeTasks
37
61
 
38
- # Emacs
62
+ ## Plugin-specific files:
63
+
64
+ # IntelliJ
65
+ /out/
66
+
67
+ # mpeltonen/sbt-idea plugin
68
+ .idea_modules/
69
+
70
+ # JIRA plugin
71
+ atlassian-ide-plugin.xml
39
72
 
73
+ # Crashlytics plugin (for Android Studio and IntelliJ)
74
+ com_crashlytics_export_strings.xml
75
+ crashlytics.properties
76
+ crashlytics-build.properties
77
+ fabric.properties
78
+
79
+ #####=== Emacs ===#####
80
+ # -*- mode: gitignore; -*-
40
81
  *~
41
- \#*
42
- .#*
82
+ \#*\#
83
+ /.emacs.desktop
84
+ /.emacs.desktop.lock
85
+ *.elc
86
+ auto-save-list
87
+ tramp
88
+ .\#*
43
89
 
44
- # Mac OS
90
+ # Org-mode
91
+ .org-id-locations
92
+ *_archive
93
+
94
+ # flymake-mode
95
+ *_flymake.*
96
+
97
+ # eshell files
98
+ /eshell/history
99
+ /eshell/lastdir
100
+
101
+ # elpa packages
102
+ /elpa/
103
+
104
+ # reftex files
105
+ *.rel
106
+
107
+ # AUCTeX auto folder
108
+ /auto/
109
+
110
+ # cask packages
111
+ .cask/
112
+ dist/
113
+
114
+ # Flycheck
115
+ flycheck_*.el
116
+
117
+ # server auth directory
118
+ /server/
119
+
120
+ # projectiles files
121
+ .projectile
122
+
123
+ # directory configuration
124
+ .dir-locals.el
45
125
 
46
- .DS_Store
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <Settings><!--This file was automatically generated by Ruby plugin.
3
+ You are allowed to:
4
+ 1. Remove rake task
5
+ 2. Add existing rake tasks
6
+ To add existing rake tasks automatically delete this file and reload the project.
7
+ --><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Run all unit tests with coverage" fullCmd="coverage" taksId="coverage" /><RakeTask description="Run unit tests, check test coverage, check code style" fullCmd="default" taksId="default" /><RakeTask description="Run RuboCop" fullCmd="rubocop" taksId="rubocop" /><RakeGroup description="" fullCmd="" taksId="rubocop"><RakeTask description="Auto-correct RuboCop offenses" fullCmd="rubocop:auto_correct" taksId="auto_correct" /></RakeGroup><RakeTask description="Run all tests" fullCmd="spec" taksId="spec" /><RakeGroup description="" fullCmd="" taksId="spec"><RakeTask description="Run all unit tests" fullCmd="spec:unit" taksId="unit" /><RakeTask description="" fullCmd="spec:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="debug_load_path" taksId="debug_load_path" /></RakeGroup></Settings>
@@ -1,24 +1,10 @@
1
- # Disable compact style check for example.rb
1
+ inherit_from: ../.rubocop.yml
2
+
3
+ # Disable various checks for sample code
2
4
  Style/ClassAndModuleChildren:
3
5
  Exclude:
4
6
  - 'example.rb'
5
7
 
6
- # Disable line-length check; it's too easy for the cure to be worse than the disease
7
- Metrics/LineLength:
8
- Enabled: False
9
-
10
- # Disable problematic module documentation check (see https://github.com/bbatsov/rubocop/issues/947)
11
- Style/Documentation:
12
- Enabled: false
13
-
14
- # Allow one line around class body (Style/EmptyLines will still disallow two or more)
15
- Style/EmptyLinesAroundClassBody:
16
- Enabled: false
17
-
18
- # Allow one line around module body (Style/EmptyLines will still disallow two or more)
19
- Style/EmptyLinesAroundModuleBody:
20
- Enabled: false
21
-
22
- # Allow one line around block body (Style/EmptyLines will still disallow two or more)
23
- Style/EmptyLinesAroundBlockBody:
24
- Enabled: false
8
+ Style/MixinUsage:
9
+ Exclude:
10
+ - 'example.rb'
@@ -1 +1 @@
1
- 2.2.3
1
+ 2.4.1
data/CHANGES.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.1.12 (14 November 2018)
2
+
3
+ - Change stash-wrapper namespace URI to https://dash.ucop.edu/stash_wrapper/ and schema location to
4
+ https://dash.ucop.edu/stash_wrapper/stash_wrapper.xsd (formerly both URLs were http://dash.cdlib.org/)
5
+ - Update to Ruby 2.4.1
6
+ - Update to Rubocop 0.57.2
7
+ - Update dependencies
8
+
1
9
  # 0.1.11.1 (5 August 2016)
2
10
 
3
11
  - In `License::CC_BY`, use "Creative Commons Attribution 4.0 International (CC BY 4.0)"
data/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 The Regents of the University of California
3
+ Copyright (c) 2018 The Regents of the University of California
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
  [![Gem Version](https://img.shields.io/gem/v/stash-wrapper.svg)](https://github.com/CDLUC3/stash-wrapper/releases)
7
7
 
8
8
  Gem for working with the [Stash](https://github.com/CDLUC3/stash)
9
- [XML wrapper format](https://dash.cdlib.org/stash_wrapper/stash_wrapper.xsd).
9
+ [XML wrapper format](https://dash.ucop.edu/stash_wrapper/stash_wrapper.xsd).
10
10
 
11
11
  The `StashWrapper` object graph mostly mirrors the `stash_wrapper` schema, though some
12
12
  simpler elements have been collapsed into object attributes. Also, some classes and
@@ -126,7 +126,7 @@ to be nonsensical.
126
126
  ### Single file to standard output
127
127
  ```
128
128
  % gen_stash_wrapper_sample
129
- <st:stash_wrapper xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://dash.cdlib.org/stash_wrapper/ http://dash.cdlib.org/stash_wrapper/stash_wrapper.xsd' xmlns:st='http://dash.cdlib.org/stash_wrapper/'>
129
+ <st:stash_wrapper xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='https://dash.ucop.edu/stash_wrapper/ https://dash.ucop.edu/stash_wrapper/stash_wrapper.xsd' xmlns:st='https://dash.ucop.edu/stash_wrapper/'>
130
130
  <st:identifier type='DOI'>10.21585/def1000001</st:identifier>
131
131
  <st:stash_administrative>
132
132
  <st:version>
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ namespace :spec do
8
8
 
9
9
  desc 'Run all unit tests'
10
10
  RSpec::Core::RakeTask.new(:unit) do |task|
11
- task.rspec_opts = %w(--color --format documentation --order default)
11
+ task.rspec_opts = %w[--color --format documentation --order default]
12
12
  task.pattern = 'unit/**/*_spec.rb'
13
13
  end
14
14
 
@@ -44,4 +44,4 @@ end
44
44
  # Defaults
45
45
 
46
46
  desc 'Run unit tests, check test coverage, check code style'
47
- task default: [:coverage, :rubocop]
47
+ task default: %i[coverage rubocop]
data/example.rb CHANGED
@@ -35,7 +35,8 @@ inventory = Inventory.new(
35
35
  StashFile.new(
36
36
  pathname: 'HSRC_MasterSampleII.sas7bdat', size_bytes: 123_456, mime_type: 'application/x-sas-data'
37
37
  )
38
- ])
38
+ ]
39
+ )
39
40
 
40
41
  datacite_file = 'spec/data/wrapper/wrapper-2-payload.xml'
41
42
  datacite_root = REXML::Document.new(File.read(datacite_file)).root
@@ -1,6 +1,6 @@
1
1
  module Stash
2
- # Code relating to the {https://dash.cdlib.org/stash_wrapper/ Stash wrapper format}
2
+ # Code relating to the {https://dash.ucop.edu/stash_wrapper/ Stash wrapper format}
3
3
  module Wrapper
4
- Dir.glob(File.expand_path('../wrapper/*.rb', __FILE__), &method(:require))
4
+ Dir.glob(File.expand_path('wrapper/*.rb', __dir__), &method(:require))
5
5
  end
6
6
  end
@@ -8,9 +8,9 @@ module Stash
8
8
 
9
9
  # See `XML::Mapping::SingleAttributeNode#initialize`
10
10
  def initialize(*args)
11
- path, *args = super(*args)
11
+ path, *myargs = super(*args)
12
12
  @path = ::XML::XXPath.new(path)
13
- args
13
+ myargs # rubocop:disable Lint/Void
14
14
  end
15
15
 
16
16
  # Extracts the children of this element as an array.
@@ -18,14 +18,9 @@ module Stash
18
18
  # @param period [String] The embargo period
19
19
  # @param start_date [Date] The embargo start date
20
20
  # @param end_date [Date] The embargo end date
21
- def initialize(type:, period:, start_date:, end_date:) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
22
- fail ArgumentError, "Specified type does not appear to be an EmbargoType: #{type || 'nil'}" unless type && type.is_a?(EmbargoType)
23
- fail ArgumentError, "Specified embargo period does not appear to be a non-empty string: #{period.inspect}" if period.to_s.strip.empty?
24
- fail ArgumentError, "Specified start date does not appear to be a date: #{start_date || 'nil'}" unless start_date && start_date.respond_to?(:iso8601)
25
- fail ArgumentError, "Specified end date does not appear to be a date: #{end_date || 'nil'}" unless end_date && end_date.respond_to?(:iso8601)
26
-
27
- self.type = type
28
- self.period = period.to_s
21
+ def initialize(type:, period:, start_date:, end_date:)
22
+ self.type = valid_type(type)
23
+ self.period = valid_period(period)
29
24
  self.start_date, self.end_date = valid_range(start_date, end_date)
30
25
  end
31
26
 
@@ -38,12 +33,27 @@ module Stash
38
33
 
39
34
  private
40
35
 
36
+ def valid_type(type)
37
+ return type if type.is_a?(EmbargoType)
38
+ raise ArgumentError, "Specified type does not appear to be an EmbargoType: #{type || 'nil'}"
39
+ end
40
+
41
+ def valid_period(period)
42
+ period_str = period.to_s
43
+ return period_str unless period_str.strip.empty?
44
+ raise ArgumentError, "Specified embargo period does not appear to be a non-empty string: #{period.inspect}"
45
+ end
46
+
41
47
  def valid_range(start_date, end_date)
42
- if start_date > end_date
43
- fail RangeError, "start_date #{start_date} must be <= end_date #{end_date}"
44
- else
45
- [start_date.to_date, end_date.to_date]
46
- end
48
+ sd = valid_date(start_date)
49
+ ed = valid_date(end_date)
50
+ raise RangeError, "start_date #{sd} must be <= end_date #{ed}" if sd > ed
51
+ [sd.to_date, ed.to_date]
52
+ end
53
+
54
+ def valid_date(date)
55
+ return date if date && date.respond_to?(:iso8601)
56
+ raise ArgumentError, "Specified date does not appear to be a date: #{date || 'nil'}"
47
57
  end
48
58
  end
49
59
  end
@@ -4,7 +4,7 @@ module Stash
4
4
  module Wrapper
5
5
  # Controlled vocabulary for {Embargo#type}
6
6
  class EmbargoType < TypesafeEnum::Base
7
- [:NONE, :DOWNLOAD, :DESCRIPTION].each { |t| new t }
7
+ %i[NONE DOWNLOAD DESCRIPTION].each { |t| new t }
8
8
  end
9
9
  end
10
10
  end
@@ -12,11 +12,15 @@ module Stash
12
12
 
13
13
  # Creates a new {Identifier}
14
14
  def initialize(type:, value:)
15
- fail ArgumentError, "Identifier type does not appear to be an IdentifierType: #{type || 'nil'}" unless type && type.is_a?(IdentifierType)
16
- fail ArgumentError, "Identifier value does not appear to be a non-empty string: #{value.inspect}" if value.to_s.strip.empty?
15
+ raise ArgumentError, "Identifier type does not appear to be an IdentifierType: #{type || 'nil'}" unless type.is_a?(IdentifierType)
16
+ raise ArgumentError, "Identifier value does not appear to be a non-empty string: #{value.inspect}" if value.to_s.strip.empty?
17
17
  self.type = type
18
18
  self.value = value
19
19
  end
20
+
21
+ def formatted
22
+ type.format(value)
23
+ end
20
24
  end
21
25
 
22
26
  end
@@ -8,6 +8,11 @@ module Stash
8
8
  new :DOI, 'DOI'
9
9
  new :HANDLE, 'Handle'
10
10
  new :URL, 'URL'
11
+
12
+ def format(id_value)
13
+ return id_value if self == URL || self == HANDLE # TODO: is this close enough?
14
+ "#{value.downcase}:#{id_value}"
15
+ end
11
16
  end
12
17
  end
13
18
  end
@@ -21,9 +21,9 @@ module Stash
21
21
  private
22
22
 
23
23
  def valid_file_array(files)
24
- fail ArgumentError, "specified file list does not appear to be an array of StashFiles: #{files.inspect}" unless files.is_a?(Array)
24
+ raise ArgumentError, "specified file list does not appear to be an array of StashFiles: #{files.inspect}" unless files.is_a?(Array)
25
25
  files.each_with_index do |f, i|
26
- fail ArgumentError, "files[#{i}] does not appear to be a StashFile: #{f.inspect}" unless f.is_a?(StashFile)
26
+ raise ArgumentError, "files[#{i}] does not appear to be a StashFile: #{f.inspect}" unless f.is_a?(StashFile)
27
27
  end
28
28
  files
29
29
  end
@@ -15,8 +15,8 @@ module Stash
15
15
  # @param uri [URI, String] The license URI
16
16
  # @raise [URI::InvalidURIError] if `uri` is a string that is not a valid URI
17
17
  def initialize(name:, uri:)
18
- fail ArgumentError, "License name does not appear to be a non-empty string: #{name.inspect}" if name.to_s.strip.empty?
19
- fail ArgumentError, 'No uri provided' unless uri
18
+ raise ArgumentError, "License name does not appear to be a non-empty string: #{name.inspect}" if name.to_s.strip.empty?
19
+ raise ArgumentError, 'No uri provided' unless uri
20
20
  self.name = name
21
21
  self.uri = ::XML::MappingExtensions.to_uri(uri)
22
22
  end
@@ -1,13 +1,13 @@
1
1
  module Stash
2
- # Code relating to the {https://dash.cdlib.org/stash_wrapper/ Stash wrapper format}
2
+ # Code relating to the {https://dash.ucop.edu/stash_wrapper/ Stash wrapper format}
3
3
  module Wrapper
4
4
  # The name of this gem
5
- NAME = 'stash-wrapper'
5
+ NAME = 'stash-wrapper'.freeze
6
6
 
7
7
  # The version of this gem
8
- VERSION = '0.1.11.1'
8
+ VERSION = '0.1.12'.freeze
9
9
 
10
10
  # The copyright notice for this gem
11
- COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'
11
+ COPYRIGHT = 'Copyright (c) 2016 The Regents of the University of California'.freeze
12
12
  end
13
13
  end
@@ -14,10 +14,16 @@ module Stash
14
14
  # Creates a new {Size}
15
15
  # @param bytes [Integer] the size in bytes
16
16
  def initialize(bytes:)
17
- fail ArgumentError, "specified file size does not appear to be an integer byte count: #{bytes || 'nil'}" unless bytes.respond_to?(:to_i) && bytes.to_i == bytes
18
- self.size = bytes
17
+ self.size = valid_size(bytes)
19
18
  self.unit = SizeUnit::BYTE
20
19
  end
20
+
21
+ private
22
+
23
+ def valid_size(bytes)
24
+ return bytes if bytes && bytes.respond_to?(:to_i) && bytes == bytes.to_i
25
+ raise ArgumentError, "specified file size does not appear to be an integer byte count: #{bytes || 'nil'}"
26
+ end
21
27
  end
22
28
 
23
29
  end
@@ -22,17 +22,37 @@ module Stash
22
22
  # is supplied, it will default to an embargo of type {EmbargoType::NONE}
23
23
  # with the current date as start and end.
24
24
  # @param inventory [Inventory, nil] the (optional) file inventory
25
- def initialize(version:, license:, embargo: nil, inventory: nil) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
26
- fail ArgumentError, "version does not appear to be a Version object: #{version || 'nil'}" unless version.is_a?(Version)
27
- fail ArgumentError, "license does not appear to be a License object: #{license || 'nil'}" unless license.is_a?(License)
28
- fail ArgumentError, "embargo does not appear to be an Embargo object: #{embargo || 'nil'}" if embargo unless embargo.is_a?(Embargo)
29
- fail ArgumentError, "inventory does not appear to be an Inventory object: #{inventory || 'nil'}" if inventory unless inventory.is_a?(Inventory)
30
-
31
- self.version = version
32
- self.license = license
33
- self.embargo = embargo || Embargo.none
34
- self.inventory = inventory
25
+ def initialize(version:, license:, embargo: nil, inventory: nil)
26
+ self.version = valid_version(version)
27
+ self.license = valid_license(license)
28
+ self.embargo = valid_embargo(embargo)
29
+ self.inventory = valid_inventory_or_nil(inventory)
35
30
  end
31
+
32
+ private
33
+
34
+ def valid_version(version)
35
+ return version if version.is_a?(Version)
36
+ raise ArgumentError, "version does not appear to be a Version object: #{version || 'nil'}"
37
+ end
38
+
39
+ def valid_license(license)
40
+ return license if license.is_a?(License)
41
+ raise ArgumentError, "license does not appear to be a License object: #{license || 'nil'}"
42
+ end
43
+
44
+ def valid_embargo(embargo)
45
+ return Embargo.none unless embargo
46
+ return embargo if embargo.is_a?(Embargo)
47
+ raise ArgumentError, "embargo does not appear to be an Embargo object: #{embargo.inspect}"
48
+ end
49
+
50
+ def valid_inventory_or_nil(inventory)
51
+ return unless inventory
52
+ return inventory if inventory.is_a?(Inventory)
53
+ raise ArgumentError, "inventory does not appear to be an Inventory object: #{inventory || 'nil'}"
54
+ end
55
+
36
56
  end
37
57
  end
38
58
  end