druid-tools 2.0.0 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f669f7b8429c7d0d95c9b7e8715afc362924911005504f75e8c9c6e9addee306
4
- data.tar.gz: dedef2151df6f1e7ca40ea664834218634e61a44190a17069a6d62973bc9f03d
3
+ metadata.gz: ae5225239dbe4cabc2b4380a386d476b73d9ae21af9f3791df9b1d44cb90f04e
4
+ data.tar.gz: 1a3274f2ba03e506cc1289715df194cbf8f6cf16b0d23a0367ee13ed0cae9e11
5
5
  SHA512:
6
- metadata.gz: a288b3e8ba6a1db699ce7737c196d65859c28f7e52513d0d32a421e39ca30702184e2c2b38eefc5a2d34665dffcc0ea75d85a88d7115989bb9689e865c1c6335
7
- data.tar.gz: 64ac1bdaa0b1c7bfc3a85f0480dca6b1387c76d47635f4a3823be95595303373d0d1d8e4bfd00f95c04ab4186ba7bc24f20fa7464b41f0c91f4f9e0f47facb3a
6
+ metadata.gz: 25274f7e81d1694cbbef1419165dc517ca40ada672a9d4a76f9c8c38781a3782520992050ce2f056f6d954a9fd74adea1c5483b3f4297d7918c512697ab1148a
7
+ data.tar.gz: 259575663aa19d712b31aa5f62f4204b6779dae6deec8512a0fba5dcb98df50af8f44d7a51b2b5b88573fd51acf9716d46e2a9bdb2a354b50f379406166e609e
@@ -0,0 +1,10 @@
1
+ version: 2.1
2
+ orbs:
3
+ ruby-rails: sul-dlss/ruby-rails@3.0.1
4
+ workflows:
5
+ build:
6
+ jobs:
7
+ - ruby-rails/lint-gem:
8
+ name: lint
9
+ - ruby-rails/test-gem:
10
+ name: test
@@ -0,0 +1,9 @@
1
+ ## Why was this change made? 🤔
2
+
3
+
4
+
5
+ ## How was this change tested? 🤨
6
+
7
+ ⚡ ⚠ If this change has cross service impact, ***run [integration tests](https://github.com/sul-dlss/infrastructure-integration-test)*** that exercise the code and/or test in [stage|qa] environment, in addition to specs. ⚡
8
+
9
+
data/.rubocop.yml CHANGED
@@ -1,41 +1,138 @@
1
1
  inherit_from: .rubocop_todo.yml
2
2
 
3
- # Turn on RSpec cops
4
3
  require: rubocop-rspec
5
4
 
6
5
  AllCops:
6
+ TargetRubyVersion: 2.7
7
7
  DisplayCopNames: true
8
- # Include:
9
- # - 'Rakefile'
10
8
  Exclude:
11
9
  - 'Gemfile.lock'
12
10
  - '**/*.md'
13
- - 'vendor/**/*' # avoid running rubocop on travis cached bundler
14
-
15
- # --- Layout ---
16
-
17
- # --- Lint ---
18
-
19
- # --- Metrics ---
20
-
21
- # because this isn't 1994
22
- Metrics/LineLength:
23
- Max: 167 # would like to reduce this to 120
11
+ - 'vendor/**/*' # avoid running rubocop on cached bundler
24
12
 
25
13
  Metrics/BlockLength:
26
14
  Exclude:
27
15
  - 'spec/**/*_spec.rb'
28
16
 
29
- # --- Naming ---
30
-
31
17
  Naming/FileName:
32
18
  Exclude:
33
19
  - Gemfile
34
20
  - druid-tools.gemspec
35
21
  - lib/druid-tools.rb
36
22
 
37
- # -- Performance ---
38
-
39
- # --- RSpec ---
40
-
41
- # --- Style ---
23
+ Gemspec/DateAssignment: # new in 1.10
24
+ Enabled: true
25
+ Gemspec/RequireMFA: # new in 1.23
26
+ Enabled: true
27
+ Layout/LineEndStringConcatenationIndentation: # new in 1.18
28
+ Enabled: true
29
+ Layout/SpaceBeforeBrackets: # new in 1.7
30
+ Enabled: true
31
+ Lint/AmbiguousAssignment: # new in 1.7
32
+ Enabled: true
33
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
34
+ Enabled: true
35
+ Lint/AmbiguousRange: # new in 1.19
36
+ Enabled: true
37
+ Lint/DeprecatedConstants: # new in 1.8
38
+ Enabled: true
39
+ Lint/DuplicateBranch: # new in 1.3
40
+ Enabled: true
41
+ Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
42
+ Enabled: true
43
+ Lint/EmptyBlock: # new in 1.1
44
+ Enabled: true
45
+ Lint/EmptyClass: # new in 1.3
46
+ Enabled: true
47
+ Lint/EmptyInPattern: # new in 1.16
48
+ Enabled: true
49
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
50
+ Enabled: true
51
+ Lint/LambdaWithoutLiteralBlock: # new in 1.8
52
+ Enabled: true
53
+ Lint/NoReturnInBeginEndBlocks: # new in 1.2
54
+ Enabled: true
55
+ Lint/NumberedParameterAssignment: # new in 1.9
56
+ Enabled: true
57
+ Lint/OrAssignmentToConstant: # new in 1.9
58
+ Enabled: true
59
+ Lint/RedundantDirGlobSort: # new in 1.8
60
+ Enabled: true
61
+ Lint/RequireRelativeSelfPath: # new in 1.22
62
+ Enabled: true
63
+ Lint/SymbolConversion: # new in 1.9
64
+ Enabled: true
65
+ Lint/ToEnumArguments: # new in 1.1
66
+ Enabled: true
67
+ Lint/TripleQuotes: # new in 1.9
68
+ Enabled: true
69
+ Lint/UnexpectedBlockArity: # new in 1.5
70
+ Enabled: true
71
+ Lint/UnmodifiedReduceAccumulator: # new in 1.1
72
+ Enabled: true
73
+ Lint/UselessRuby2Keywords: # new in 1.23
74
+ Enabled: true
75
+ Naming/BlockForwarding: # new in 1.24
76
+ Enabled: true
77
+ Security/IoMethods: # new in 1.22
78
+ Enabled: true
79
+ Style/ArgumentsForwarding: # new in 1.1
80
+ Enabled: true
81
+ Style/CollectionCompact: # new in 1.2
82
+ Enabled: true
83
+ Style/DocumentDynamicEvalDefinition: # new in 1.1
84
+ Enabled: true
85
+ Style/EndlessMethod: # new in 1.8
86
+ Enabled: true
87
+ Style/FileRead: # new in 1.24
88
+ Enabled: true
89
+ Style/FileWrite: # new in 1.24
90
+ Enabled: true
91
+ Style/HashConversion: # new in 1.10
92
+ Enabled: true
93
+ Style/HashExcept: # new in 1.7
94
+ Enabled: true
95
+ Style/IfWithBooleanLiteralBranches: # new in 1.9
96
+ Enabled: true
97
+ Style/InPatternThen: # new in 1.16
98
+ Enabled: true
99
+ Style/MapToHash: # new in 1.24
100
+ Enabled: true
101
+ Style/MultilineInPatternThen: # new in 1.16
102
+ Enabled: true
103
+ Style/NegatedIfElseCondition: # new in 1.2
104
+ Enabled: true
105
+ Style/NilLambda: # new in 1.3
106
+ Enabled: true
107
+ Style/NumberedParameters: # new in 1.22
108
+ Enabled: true
109
+ Style/NumberedParametersLimit: # new in 1.22
110
+ Enabled: true
111
+ Style/OpenStructUse: # new in 1.23
112
+ Enabled: true
113
+ Style/QuotedSymbols: # new in 1.16
114
+ Enabled: true
115
+ Style/RedundantArgument: # new in 1.4
116
+ Enabled: true
117
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
118
+ Enabled: true
119
+ Style/SelectByRegexp: # new in 1.22
120
+ Enabled: true
121
+ Style/StringChars: # new in 1.12
122
+ Enabled: true
123
+ Style/SwapValues: # new in 1.1
124
+ Enabled: true
125
+ RSpec/BeEq: # new in 2.9.0
126
+ Enabled: true
127
+ RSpec/BeNil: # new in 2.9.0
128
+ Enabled: true
129
+ RSpec/ExcessiveDocstringSpacing: # new in 2.5
130
+ Enabled: true
131
+ RSpec/IdenticalEqualityAssertion: # new in 2.4
132
+ Enabled: true
133
+ RSpec/SubjectDeclaration: # new in 2.5
134
+ Enabled: true
135
+ RSpec/FactoryBot/SyntaxMethods: # new in 2.7
136
+ Enabled: true
137
+ RSpec/Rails/AvoidSetupHook: # new in 2.4
138
+ Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,29 +1,32 @@
1
1
  # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2019-05-24 07:28:47 -0400 using RuboCop version 0.70.0.
2
+ # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
+ # on 2022-04-01 18:08:00 UTC using RuboCop version 1.26.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 1
10
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes, Max.
10
11
  Metrics/AbcSize:
11
- Max: 21
12
+ Exclude:
13
+ - 'lib/druid_tools/druid.rb'
12
14
 
13
15
  # Offense count: 1
14
- # Configuration parameters: CountComments.
16
+ # Configuration parameters: CountComments, Max, CountAsOne.
15
17
  Metrics/ClassLength:
16
- Max: 140
18
+ Exclude:
19
+ - 'lib/druid_tools/druid.rb'
17
20
 
18
21
  # Offense count: 1
19
- # Configuration parameters: CountComments, ExcludedMethods.
20
- Metrics/MethodLength:
21
- Max: 12
22
+ # Configuration parameters: IgnoredMethods, Max.
23
+ Metrics/CyclomaticComplexity:
24
+ Exclude:
25
+ - 'lib/druid_tools/druid.rb'
22
26
 
23
27
  # Offense count: 1
24
- # Configuration parameters: Blacklist.
25
- # Blacklist: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
26
- Naming/HeredocDelimiterNaming:
28
+ # Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, IgnoredMethods.
29
+ Metrics/MethodLength:
27
30
  Exclude:
28
31
  - 'lib/druid_tools/druid.rb'
29
32
 
@@ -35,22 +38,30 @@ RSpec/BeforeAfterAll:
35
38
  - 'spec/support/**/*.rb'
36
39
  - 'spec/druid_tools_spec.rb'
37
40
 
38
- # Offense count: 10
39
- # Configuration parameters: Max.
41
+ # Offense count: 8
42
+ # Configuration parameters: Max, CountAsOne.
40
43
  RSpec/ExampleLength:
41
44
  Exclude:
42
45
  - 'spec/druid_tools_spec.rb'
43
46
 
44
47
  # Offense count: 1
45
- # Configuration parameters: CustomTransform, IgnoreMethods.
48
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
49
+ # Include: **/*_spec*rb*, **/spec/**/*
46
50
  RSpec/FilePath:
47
51
  Exclude:
48
52
  - 'spec/druid_tools_spec.rb'
49
53
 
50
- # Offense count: 22
51
- # Configuration parameters: AggregateFailuresByDefault.
54
+ # Offense count: 16
55
+ # Configuration parameters: Max.
52
56
  RSpec/MultipleExpectations:
53
- Max: 11
57
+ Exclude:
58
+ - 'spec/druid_tools_spec.rb'
59
+
60
+ # Offense count: 4
61
+ # Configuration parameters: AllowSubject, Max.
62
+ RSpec/MultipleMemoizedHelpers:
63
+ Exclude:
64
+ - 'spec/druid_tools_spec.rb'
54
65
 
55
66
  # Offense count: 2
56
67
  RSpec/RepeatedExample:
@@ -58,19 +69,32 @@ RSpec/RepeatedExample:
58
69
  - 'spec/druid_tools_spec.rb'
59
70
 
60
71
  # Offense count: 1
61
- Style/ClassVars:
62
- Exclude:
63
- - 'lib/druid_tools/druid.rb'
64
-
65
- # Offense count: 2
72
+ # Configuration parameters: AllowedConstants.
66
73
  Style/Documentation:
67
74
  Exclude:
68
75
  - 'spec/**/*'
69
76
  - 'test/**/*'
70
- - 'lib/druid_tools.rb'
71
77
  - 'lib/druid_tools/druid.rb'
72
78
 
73
79
  # Offense count: 1
74
- Style/EvalWithLocation:
80
+ # This cop supports safe auto-correction (--auto-correct).
81
+ Style/IfUnlessModifier:
75
82
  Exclude:
76
83
  - 'lib/druid_tools/druid.rb'
84
+
85
+ # Offense count: 8
86
+ # Configuration parameters: AllowedMethods.
87
+ # AllowedMethods: respond_to_missing?
88
+ Style/OptionalBooleanParameter:
89
+ Exclude:
90
+ - 'lib/druid_tools/access_druid.rb'
91
+ - 'lib/druid_tools/druid.rb'
92
+
93
+ # Offense count: 2
94
+ # This cop supports safe auto-correction (--auto-correct).
95
+ # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
96
+ # URISchemes: http, https
97
+ Layout/LineLength:
98
+ Exclude:
99
+ - 'lib/druid_tools/druid.rb'
100
+ - 'spec/druid_tools_spec.rb'
data/Gemfile CHANGED
@@ -3,11 +3,7 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  group :development do
6
- gem 'debugger', platform: :ruby_19
7
- gem 'pry-debugger', platform: :ruby_19
8
- gem 'rcov', platform: :ruby_18
9
- gem 'ruby-debug', platform: :ruby_18
10
- gem 'simplecov', platform: %i[ruby_19 ruby_20]
6
+ gem 'byebug'
11
7
  end
12
8
 
13
9
  gemspec
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- [![Build Status](https://travis-ci.org/sul-dlss/druid-tools.svg?branch=delete-records)](https://travis-ci.org/sul-dlss/druid-tools)
2
- [![Coverage Status](https://coveralls.io/repos/github/sul-dlss/druid-tools/badge.svg?branch=master)](https://coveralls.io/github/sul-dlss/druid-tools?branch=master)
1
+ [![CircleCI](https://circleci.com/gh/sul-dlss/druid-tools/tree/main.svg?style=svg)](https://circleci.com/gh/sul-dlss/druid-tools/tree/main)
3
2
  [![Gem Version](https://badge.fury.io/rb/druid-tools.svg)](https://badge.fury.io/rb/druid-tools)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/a21a8f4d0abae265638e/test_coverage)](https://codeclimate.com/github/sul-dlss/druid-tools/test_coverage)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/a21a8f4d0abae265638e/maintainability)](https://codeclimate.com/github/sul-dlss/druid-tools/maintainability)
4
5
 
5
6
  # Druid::Tools
6
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.0
1
+ 2.2.1
data/druid-tools.gemspec CHANGED
@@ -7,7 +7,9 @@ Gem::Specification.new do |gem|
7
7
  gem.summary = 'Tools to manipulate DRUID trees and content directories'
8
8
  gem.homepage = 'http://github.com/sul-dlss/druid-tools'
9
9
  gem.licenses = ['ALv2', 'Stanford University Libraries']
10
- gem.has_rdoc = true
10
+ gem.metadata['rubygems_mfa_required'] = 'true'
11
+
12
+ gem.required_ruby_version = '>= 2.7'
11
13
 
12
14
  gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
13
15
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
@@ -16,9 +18,10 @@ Gem::Specification.new do |gem|
16
18
  gem.require_paths = ['lib']
17
19
  gem.version = File.read('VERSION').strip
18
20
 
21
+ gem.add_dependency 'deprecation'
19
22
  gem.add_development_dependency 'coveralls'
20
23
  gem.add_development_dependency 'rake', '>= 10.1.0'
21
24
  gem.add_development_dependency 'rspec', '~> 3.0'
22
- gem.add_development_dependency 'rubocop', '~> 0.70.0'
23
- gem.add_development_dependency 'rubocop-rspec', '~> 1.33.0'
25
+ gem.add_development_dependency 'rubocop'
26
+ gem.add_development_dependency 'rubocop-rspec'
24
27
  end
@@ -15,6 +15,10 @@ module DruidTools
15
15
  mkdir(extra) if create && !File.exist?(result)
16
16
  result
17
17
  end
18
+
19
+ def pruning_base
20
+ pathname
21
+ end
18
22
  end
19
23
 
20
24
  PurlDruid = AccessDruid
@@ -2,9 +2,13 @@
2
2
 
3
3
  require 'pathname'
4
4
  require 'fileutils'
5
+ require 'deprecation'
5
6
 
6
7
  module DruidTools
7
8
  class Druid
9
+ extend Deprecation
10
+ self.deprecation_horizon = 'druid-tools 3.0.0'
11
+
8
12
  attr_accessor :druid, :base
9
13
 
10
14
  # See https://consul.stanford.edu/pages/viewpage.action?title=SURI+2.0+Specification&spaceKey=chimera
@@ -41,16 +45,28 @@ module DruidTools
41
45
  end
42
46
  self.prefix = 'druid'
43
47
 
44
- %i[content metadata temp].each do |dir_type|
45
- class_eval <<-EOC
46
- def #{dir_type}_dir(create=true)
47
- path("#{dir_type}",create)
48
- end
48
+ def content_dir(create = true)
49
+ path('content', create)
50
+ end
49
51
 
50
- def find_#{dir_type}(path)
51
- find(:#{dir_type},path)
52
- end
53
- EOC
52
+ def metadata_dir(create = true)
53
+ path('metadata', create)
54
+ end
55
+
56
+ def temp_dir(create = true)
57
+ path('temp', create)
58
+ end
59
+
60
+ def find_content(path)
61
+ find(:content, path)
62
+ end
63
+
64
+ def find_metadata(path)
65
+ find(:metadata, path)
66
+ end
67
+
68
+ def find_temp(path)
69
+ find(:temp, path)
54
70
  end
55
71
 
56
72
  # @param druid [String] A valid druid
@@ -66,7 +82,7 @@ module DruidTools
66
82
  end
67
83
 
68
84
  def id
69
- @druid.scan(self.class.pattern).flatten.join('')
85
+ @druid.scan(self.class.pattern).flatten.join
70
86
  end
71
87
 
72
88
  def tree
@@ -122,6 +138,7 @@ module DruidTools
122
138
  FileUtils.mkdir_p(real_path)
123
139
  FileUtils.ln_s(source, new_path, force: true)
124
140
  end
141
+ deprecation_deprecate :mkdir_with_final_link
125
142
 
126
143
  def rmdir(extra = nil)
127
144
  parts = tree
@@ -137,6 +154,7 @@ module DruidTools
137
154
  parts.pop
138
155
  end
139
156
  end
157
+ deprecation_deprecate :rmdir
140
158
 
141
159
  def pathname
142
160
  Pathname path
@@ -146,12 +164,15 @@ module DruidTools
146
164
  Pathname base
147
165
  end
148
166
 
167
+ def pruning_base
168
+ pathname.parent
169
+ end
170
+
149
171
  def prune!
150
- this_path = pathname
151
- parent = this_path.parent
152
- parent.rmtree if parent.exist? && parent != base_pathname
153
- prune_ancestors parent.parent
172
+ pruning_base.rmtree if pruning_base.exist? && pruning_base != base_pathname
173
+ prune_ancestors pruning_base.parent
154
174
  end
175
+ deprecation_deprecate :prune!
155
176
 
156
177
  # @param [Pathname] outermost_branch The branch at which pruning begins
157
178
  # @return [void] Ascend the druid tree and prune empty branches
@@ -162,5 +183,6 @@ module DruidTools
162
183
  break if outermost_branch == base_pathname
163
184
  end
164
185
  end
186
+ deprecation_deprecate :prune_ancestors
165
187
  end
166
188
  end
@@ -5,7 +5,8 @@ require 'spec_helper'
5
5
  RSpec.describe DruidTools::PurlDruid do
6
6
  let(:purl_root) { Dir.mktmpdir }
7
7
 
8
- let(:druid) { described_class.new 'druid:cd456ef7890', purl_root }
8
+ let(:druid) { described_class.new druid_str, purl_root }
9
+ let(:druid_str) { 'druid:cd456ef7890' }
9
10
 
10
11
  after do
11
12
  FileUtils.remove_entry purl_root
@@ -15,6 +16,12 @@ RSpec.describe DruidTools::PurlDruid do
15
16
  expect(druid.tree).to eq(%w[cd 456 ef 7890])
16
17
  end
17
18
 
19
+ describe '#pruning_base' do
20
+ subject(:path) { described_class.new(druid_str).pruning_base }
21
+
22
+ it { is_expected.to eq(Pathname.new('./cd/456/ef/7890')) }
23
+ end
24
+
18
25
  describe '#content_dir' do
19
26
  it 'creates content directories at leaf of the druid tree' do
20
27
  expect(druid.content_dir).to match(%r{ef/7890$})
@@ -6,6 +6,8 @@ RSpec.describe DruidTools::Druid do
6
6
  let(:tree1) { File.join(fixture_dir, 'cd/456/ef/7890/cd456ef7890') }
7
7
  let(:strictly_valid_druid_str) { 'druid:cd456gh1234' }
8
8
  let(:tree2) { File.join(fixture_dir, 'cd/456/gh/1234/cd456gh1234') }
9
+ let(:access_druid_str) { 'druid:cd456ef9999' }
10
+ let(:tree3) { File.join(fixture_dir, 'cd/456/ef/9999') }
9
11
 
10
12
  after do
11
13
  FileUtils.rm_rf(File.join(fixture_dir, 'cd'))
@@ -41,6 +43,7 @@ RSpec.describe DruidTools::Druid do
41
43
  expect(described_class.valid?(dru, false)).to eq(exp)
42
44
  end
43
45
  end
46
+
44
47
  context 'with strict validation' do
45
48
  it 'correctly validates druid strings' do
46
49
  tests = [
@@ -82,6 +85,12 @@ RSpec.describe DruidTools::Druid do
82
85
  end
83
86
  end
84
87
 
88
+ describe '#pruning_base' do
89
+ subject(:path) { described_class.new(druid_str).pruning_base }
90
+
91
+ it { is_expected.to eq(Pathname.new('./cd/456/ef/7890')) }
92
+ end
93
+
85
94
  it '#druid provides the full druid including the prefix' do
86
95
  expect(described_class.new('druid:cd456ef7890', fixture_dir).druid).to eq('druid:cd456ef7890')
87
96
  expect(described_class.new('cd456ef7890', fixture_dir).druid).to eq('druid:cd456ef7890')
@@ -97,6 +106,7 @@ RSpec.describe DruidTools::Druid do
97
106
  expect { described_class.new('nondruid:cd456ef7890', fixture_dir) }.to raise_error(ArgumentError)
98
107
  expect { described_class.new('druid:cd4567ef890', fixture_dir) }.to raise_error(ArgumentError)
99
108
  end
109
+
100
110
  it 'takes strict argument' do
101
111
  described_class.new(strictly_valid_druid_str, fixture_dir, true)
102
112
  expect { described_class.new(druid_str, fixture_dir, true) }.to raise_error(ArgumentError)
@@ -109,29 +119,46 @@ RSpec.describe DruidTools::Druid do
109
119
  expect(druid.path).to eq(tree1)
110
120
  end
111
121
 
112
- it '#mkdir, #rmdir create and destroy druid directories' do
113
- expect(File.exist?(tree1)).to eq false
114
- expect(File.exist?(tree2)).to eq false
122
+ it '#mkdir creates, and #rmdir destroys, *only* the expected druid directory' do
123
+ allow(Deprecation).to receive(:warn)
124
+ expect(File.exist?(tree1)).to be false
125
+ expect(File.exist?(tree2)).to be false
126
+ expect(File.exist?(tree3)).to be false
115
127
 
116
128
  druid1 = described_class.new(druid_str, fixture_dir)
117
129
  druid2 = described_class.new(strictly_valid_druid_str, fixture_dir)
130
+ druid3 = DruidTools::AccessDruid.new(access_druid_str, fixture_dir)
118
131
 
119
132
  druid1.mkdir
120
- expect(File.exist?(tree1)).to eq true
121
- expect(File.exist?(tree2)).to eq false
133
+ expect(File.exist?(tree1)).to be true
134
+ expect(File.exist?(tree2)).to be false
135
+ expect(File.exist?(tree3)).to be false
122
136
 
123
137
  druid2.mkdir
124
- expect(File.exist?(tree1)).to eq true
125
- expect(File.exist?(tree2)).to eq true
138
+ expect(File.exist?(tree1)).to be true
139
+ expect(File.exist?(tree2)).to be true
140
+ expect(File.exist?(tree3)).to be false
141
+
142
+ druid3.mkdir
143
+ expect(File.exist?(tree1)).to be true
144
+ expect(File.exist?(tree2)).to be true
145
+ expect(File.exist?(tree3)).to be true
146
+
147
+ druid3.rmdir
148
+ expect(File.exist?(tree1)).to be true
149
+ expect(File.exist?(tree2)).to be true
150
+ expect(File.exist?(tree3)).to be false
126
151
 
127
152
  druid2.rmdir
128
- expect(File.exist?(tree1)).to eq true
129
- expect(File.exist?(tree2)).to eq false
153
+ expect(File.exist?(tree1)).to be true
154
+ expect(File.exist?(tree2)).to be false
155
+ expect(File.exist?(tree3)).to be false
130
156
 
131
157
  druid1.rmdir
132
- expect(File.exist?(tree1)).to eq false
133
- expect(File.exist?(tree2)).to eq false
134
- expect(File.exist?(File.join(fixture_dir, 'cd'))).to eq false
158
+ expect(File.exist?(tree1)).to be false
159
+ expect(File.exist?(tree2)).to be false
160
+ expect(File.exist?(tree3)).to be false
161
+ expect(File.exist?(File.join(fixture_dir, 'cd'))).to be false
135
162
  end
136
163
 
137
164
  describe 'alternate prefixes' do
@@ -157,9 +184,9 @@ RSpec.describe DruidTools::Druid do
157
184
  expect(druid.metadata_dir(false)).to eq(File.join(tree1, 'metadata'))
158
185
  expect(druid.temp_dir(false)).to eq(File.join(tree1, 'temp'))
159
186
 
160
- expect(File.exist?(File.join(tree1, 'content'))).to eq false
161
- expect(File.exist?(File.join(tree1, 'metadata'))).to eq false
162
- expect(File.exist?(File.join(tree1, 'temp'))).to eq false
187
+ expect(File.exist?(File.join(tree1, 'content'))).to be false
188
+ expect(File.exist?(File.join(tree1, 'metadata'))).to be false
189
+ expect(File.exist?(File.join(tree1, 'temp'))).to be false
163
190
  end
164
191
 
165
192
  it 'creates its content directories on the fly' do
@@ -168,9 +195,9 @@ RSpec.describe DruidTools::Druid do
168
195
  expect(druid.metadata_dir).to eq(File.join(tree1, 'metadata'))
169
196
  expect(druid.temp_dir).to eq(File.join(tree1, 'temp'))
170
197
 
171
- expect(File.exist?(File.join(tree1, 'content'))).to eq true
172
- expect(File.exist?(File.join(tree1, 'metadata'))).to eq true
173
- expect(File.exist?(File.join(tree1, 'temp'))).to eq true
198
+ expect(File.exist?(File.join(tree1, 'content'))).to be true
199
+ expect(File.exist?(File.join(tree1, 'metadata'))).to be true
200
+ expect(File.exist?(File.join(tree1, 'temp'))).to be true
174
201
  end
175
202
 
176
203
  it 'matches glob' do
@@ -178,6 +205,7 @@ RSpec.describe DruidTools::Druid do
178
205
  druid.mkdir
179
206
  expect(Dir.glob(File.join(File.dirname(druid.path), described_class.glob)).size).to eq(1)
180
207
  end
208
+
181
209
  it 'matches strict_glob' do
182
210
  druid = described_class.new(druid_str, fixture_dir)
183
211
  druid.mkdir
@@ -194,31 +222,31 @@ RSpec.describe DruidTools::Druid do
194
222
 
195
223
  it 'finds content in content directories' do
196
224
  location = druid.content_dir
197
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
225
+ File.write(File.join(location, 'someContent'), 'This is the content')
198
226
  expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
199
227
  end
200
228
 
201
229
  it 'finds content in the root directory' do
202
230
  location = druid.path(nil, true)
203
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
231
+ File.write(File.join(location, 'someContent'), 'This is the content')
204
232
  expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
205
233
  end
206
234
 
207
235
  it 'finds content in the leaf directory' do
208
236
  location = File.expand_path('..', druid.path(nil, true))
209
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
237
+ File.write(File.join(location, 'someContent'), 'This is the content')
210
238
  expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
211
239
  end
212
240
 
213
241
  it 'does not find content in the wrong content directory' do
214
242
  location = druid.metadata_dir
215
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
243
+ File.write(File.join(location, 'someContent'), 'This is the content')
216
244
  expect(druid.find_content('someContent')).to be_nil
217
245
  end
218
246
 
219
247
  it 'does not find content in a higher-up directory' do
220
248
  location = File.expand_path('../..', druid.path(nil, true))
221
- File.open(File.join(location, 'someContent'), 'w') { |f| f.write 'This is the content' }
249
+ File.write(File.join(location, 'someContent'), 'This is the content')
222
250
  expect(druid.find_content('someContent')).to be_nil
223
251
  end
224
252
 
@@ -269,7 +297,10 @@ RSpec.describe DruidTools::Druid do
269
297
  source_dir = '/tmp/content_dir'
270
298
  FileUtils.mkdir_p(source_dir)
271
299
  dr = described_class.new(strictly_valid_druid_str, fixture_dir)
272
- dr.mkdir_with_final_link(source_dir)
300
+ new_path = dr.path
301
+ FileUtils.mkdir_p(File.expand_path('..', new_path))
302
+ FileUtils.ln_s(source_dir, new_path, force: true)
303
+
273
304
  expect { dr.mkdir }.to raise_error(DruidTools::DifferentContentExistsError)
274
305
  end
275
306
  end
@@ -279,6 +310,7 @@ RSpec.describe DruidTools::Druid do
279
310
  let(:druid_obj) { described_class.new(strictly_valid_druid_str, fixture_dir) }
280
311
 
281
312
  before do
313
+ allow(Deprecation).to receive(:warn)
282
314
  FileUtils.mkdir_p(source_dir)
283
315
  end
284
316
 
@@ -304,12 +336,43 @@ RSpec.describe DruidTools::Druid do
304
336
  let(:workspace) { Dir.mktmpdir }
305
337
  let(:dr1) { described_class.new(druid_str, workspace) }
306
338
  let(:dr2) { described_class.new(strictly_valid_druid_str, workspace) }
339
+ let(:dr3) { DruidTools::AccessDruid.new(access_druid_str, workspace) }
307
340
  let(:pathname1) { dr1.pathname }
308
341
 
342
+ before do
343
+ allow(Deprecation).to receive(:warn)
344
+ end
345
+
309
346
  after do
310
347
  FileUtils.remove_entry workspace
311
348
  end
312
349
 
350
+ context 'with an access druid sharing the first three path segments' do
351
+ before do
352
+ # Nil the create records for this context because we're in a known read only one
353
+ dr1.mkdir
354
+ dr2.mkdir
355
+ dr3.mkdir
356
+ dr3.prune!
357
+ end
358
+
359
+ it 'deletes the outermost directory' do
360
+ expect(File).not_to exist(dr3.pruning_base)
361
+ end
362
+
363
+ it 'does not delete unrelated ancestor directories' do
364
+ expect(File).to exist(dr1.pruning_base)
365
+ expect(File).to exist(dr1.pruning_base.parent)
366
+ end
367
+
368
+ it 'stops at ancestor directories that have children' do
369
+ # 'cd/456/ef' should still exist because of dr1
370
+ shared_ancestor = dr1.pruning_base.parent
371
+ expect(shared_ancestor.to_s).to match(%r{cd/456/ef$})
372
+ expect(File).to exist(shared_ancestor)
373
+ end
374
+ end
375
+
313
376
  context 'when there is a shared ancestor' do
314
377
  before do
315
378
  # Nil the create records for this context because we're in a known read only one
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: druid-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -9,8 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-05-28 00:00:00.000000000 Z
12
+ date: 2022-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: deprecation
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
14
28
  - !ruby/object:Gem::Dependency
15
29
  name: coveralls
16
30
  requirement: !ruby/object:Gem::Requirement
@@ -57,30 +71,30 @@ dependencies:
57
71
  name: rubocop
58
72
  requirement: !ruby/object:Gem::Requirement
59
73
  requirements:
60
- - - "~>"
74
+ - - ">="
61
75
  - !ruby/object:Gem::Version
62
- version: 0.70.0
76
+ version: '0'
63
77
  type: :development
64
78
  prerelease: false
65
79
  version_requirements: !ruby/object:Gem::Requirement
66
80
  requirements:
67
- - - "~>"
81
+ - - ">="
68
82
  - !ruby/object:Gem::Version
69
- version: 0.70.0
83
+ version: '0'
70
84
  - !ruby/object:Gem::Dependency
71
85
  name: rubocop-rspec
72
86
  requirement: !ruby/object:Gem::Requirement
73
87
  requirements:
74
- - - "~>"
88
+ - - ">="
75
89
  - !ruby/object:Gem::Version
76
- version: 1.33.0
90
+ version: '0'
77
91
  type: :development
78
92
  prerelease: false
79
93
  version_requirements: !ruby/object:Gem::Requirement
80
94
  requirements:
81
- - - "~>"
95
+ - - ">="
82
96
  - !ruby/object:Gem::Version
83
- version: 1.33.0
97
+ version: '0'
84
98
  description: Tools to manipulate DRUID trees and content directories
85
99
  email:
86
100
  - mbklein@stanford.edu
@@ -88,11 +102,12 @@ executables: []
88
102
  extensions: []
89
103
  extra_rdoc_files: []
90
104
  files:
105
+ - ".circleci/config.yml"
106
+ - ".github/pull_request_template.md"
91
107
  - ".gitignore"
92
108
  - ".rspec"
93
109
  - ".rubocop.yml"
94
110
  - ".rubocop_todo.yml"
95
- - ".travis.yml"
96
111
  - Gemfile
97
112
  - LICENSE
98
113
  - README.md
@@ -112,7 +127,8 @@ homepage: http://github.com/sul-dlss/druid-tools
112
127
  licenses:
113
128
  - ALv2
114
129
  - Stanford University Libraries
115
- metadata: {}
130
+ metadata:
131
+ rubygems_mfa_required: 'true'
116
132
  post_install_message:
117
133
  rdoc_options: []
118
134
  require_paths:
@@ -121,15 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
121
137
  requirements:
122
138
  - - ">="
123
139
  - !ruby/object:Gem::Version
124
- version: '0'
140
+ version: '2.7'
125
141
  required_rubygems_version: !ruby/object:Gem::Requirement
126
142
  requirements:
127
143
  - - ">="
128
144
  - !ruby/object:Gem::Version
129
145
  version: '0'
130
146
  requirements: []
131
- rubyforge_project:
132
- rubygems_version: 2.7.6
147
+ rubygems_version: 3.2.32
133
148
  signing_key:
134
149
  specification_version: 4
135
150
  summary: Tools to manipulate DRUID trees and content directories
data/.travis.yml DELETED
@@ -1,16 +0,0 @@
1
- notifications:
2
- email: false
3
-
4
- rvm:
5
- - 2.4.6
6
- - 2.5.5
7
- - 2.6.3
8
-
9
- # script, expressed as an array, is necessary for 'bundle exec coveralls push' to work locally
10
- script:
11
- - bundle exec rake
12
-
13
- cache: bundler
14
-
15
- before_install:
16
- - gem install bundler # the default version of bundler for ruby 2.1 is out of date.