druid-tools 2.1.0 → 2.2.0

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: 01fc970eff4953a9530606f133d2d91c2bebeda6b1d182d472f47dae1f54d67b
4
- data.tar.gz: 7bb69909e6b552d2a5bb1f9cf1a4089e38b3696bcf250843d6754ed9dc238360
3
+ metadata.gz: d5dc0962b18ff34e8085117a830f53761c49ba2bec46938ce9c3c660480c30aa
4
+ data.tar.gz: b30f1011c1f67e7e9f189af18c63b636411c72458b20e8e0e9acd2ab27c14efd
5
5
  SHA512:
6
- metadata.gz: 8b4d19d3d554ebe71afa477780265dccc1ee2bef4ccec0a683cae16df64bc2dd66a6c52b540b05390cd0d62b8aa569bb8f6162d0fa233180a0a938f6b33cb363
7
- data.tar.gz: c6b7f6ba698164350a8704703d16dc1c5b8a8e6da36173b7c1944d7275a508d785fbaaf1938baa862c987a11c475987ff1d82bd55586e43fdf43ac908c7dfcc1
6
+ metadata.gz: 6003ded589605e4a8634b966a6789b3ec482421e339bdfb07449fac3352c8c849b215c3346224b33518f2141e556bd008b7986e0bc46d2cfc523d2babb30adcf
7
+ data.tar.gz: 6db961fbe64227aa86bd02e6835e57187a6f833574b60d9f5c12511a48b40cb34dfe69d1648608771291f07b36a2de47fa33f18abd8e1fd2f802087a35eaa50d
@@ -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: 3.0
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/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.1.0
1
+ 2.2.0
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 = '>= 3.0'
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) }
@@ -20,6 +22,6 @@ Gem::Specification.new do |gem|
20
22
  gem.add_development_dependency 'coveralls'
21
23
  gem.add_development_dependency 'rake', '>= 10.1.0'
22
24
  gem.add_development_dependency 'rspec', '~> 3.0'
23
- gem.add_development_dependency 'rubocop', '~> 0.70.0'
24
- gem.add_development_dependency 'rubocop-rspec', '~> 1.33.0'
25
+ gem.add_development_dependency 'rubocop'
26
+ gem.add_development_dependency 'rubocop-rspec'
25
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
@@ -82,7 +82,7 @@ module DruidTools
82
82
  end
83
83
 
84
84
  def id
85
- @druid.scan(self.class.pattern).flatten.join('')
85
+ @druid.scan(self.class.pattern).flatten.join
86
86
  end
87
87
 
88
88
  def tree
@@ -164,11 +164,13 @@ module DruidTools
164
164
  Pathname base
165
165
  end
166
166
 
167
+ def pruning_base
168
+ pathname.parent
169
+ end
170
+
167
171
  def prune!
168
- this_path = pathname
169
- parent = this_path.parent
170
- parent.rmtree if parent.exist? && parent != base_pathname
171
- prune_ancestors parent.parent
172
+ pruning_base.rmtree if pruning_base.exist? && pruning_base != base_pathname
173
+ prune_ancestors pruning_base.parent
172
174
  end
173
175
  deprecation_deprecate :prune!
174
176
 
@@ -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,30 +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
122
+ it '#mkdir creates, and #rmdir destroys, *only* the expected druid directory' do
113
123
  allow(Deprecation).to receive(:warn)
114
- expect(File.exist?(tree1)).to eq false
115
- expect(File.exist?(tree2)).to eq false
124
+ expect(File.exist?(tree1)).to be false
125
+ expect(File.exist?(tree2)).to be false
126
+ expect(File.exist?(tree3)).to be false
116
127
 
117
128
  druid1 = described_class.new(druid_str, fixture_dir)
118
129
  druid2 = described_class.new(strictly_valid_druid_str, fixture_dir)
130
+ druid3 = DruidTools::AccessDruid.new(access_druid_str, fixture_dir)
119
131
 
120
132
  druid1.mkdir
121
- expect(File.exist?(tree1)).to eq true
122
- 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
123
136
 
124
137
  druid2.mkdir
125
- expect(File.exist?(tree1)).to eq true
126
- 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
127
151
 
128
152
  druid2.rmdir
129
- expect(File.exist?(tree1)).to eq true
130
- 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
131
156
 
132
157
  druid1.rmdir
133
- expect(File.exist?(tree1)).to eq false
134
- expect(File.exist?(tree2)).to eq false
135
- 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
136
162
  end
137
163
 
138
164
  describe 'alternate prefixes' do
@@ -158,9 +184,9 @@ RSpec.describe DruidTools::Druid do
158
184
  expect(druid.metadata_dir(false)).to eq(File.join(tree1, 'metadata'))
159
185
  expect(druid.temp_dir(false)).to eq(File.join(tree1, 'temp'))
160
186
 
161
- expect(File.exist?(File.join(tree1, 'content'))).to eq false
162
- expect(File.exist?(File.join(tree1, 'metadata'))).to eq false
163
- 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
164
190
  end
165
191
 
166
192
  it 'creates its content directories on the fly' do
@@ -169,9 +195,9 @@ RSpec.describe DruidTools::Druid do
169
195
  expect(druid.metadata_dir).to eq(File.join(tree1, 'metadata'))
170
196
  expect(druid.temp_dir).to eq(File.join(tree1, 'temp'))
171
197
 
172
- expect(File.exist?(File.join(tree1, 'content'))).to eq true
173
- expect(File.exist?(File.join(tree1, 'metadata'))).to eq true
174
- 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
175
201
  end
176
202
 
177
203
  it 'matches glob' do
@@ -179,6 +205,7 @@ RSpec.describe DruidTools::Druid do
179
205
  druid.mkdir
180
206
  expect(Dir.glob(File.join(File.dirname(druid.path), described_class.glob)).size).to eq(1)
181
207
  end
208
+
182
209
  it 'matches strict_glob' do
183
210
  druid = described_class.new(druid_str, fixture_dir)
184
211
  druid.mkdir
@@ -195,31 +222,31 @@ RSpec.describe DruidTools::Druid do
195
222
 
196
223
  it 'finds content in content directories' do
197
224
  location = druid.content_dir
198
- 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')
199
226
  expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
200
227
  end
201
228
 
202
229
  it 'finds content in the root directory' do
203
230
  location = druid.path(nil, true)
204
- 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')
205
232
  expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
206
233
  end
207
234
 
208
235
  it 'finds content in the leaf directory' do
209
236
  location = File.expand_path('..', druid.path(nil, true))
210
- 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')
211
238
  expect(druid.find_content('someContent')).to eq(File.join(location, 'someContent'))
212
239
  end
213
240
 
214
241
  it 'does not find content in the wrong content directory' do
215
242
  location = druid.metadata_dir
216
- 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')
217
244
  expect(druid.find_content('someContent')).to be_nil
218
245
  end
219
246
 
220
247
  it 'does not find content in a higher-up directory' do
221
248
  location = File.expand_path('../..', druid.path(nil, true))
222
- 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')
223
250
  expect(druid.find_content('someContent')).to be_nil
224
251
  end
225
252
 
@@ -309,6 +336,7 @@ RSpec.describe DruidTools::Druid do
309
336
  let(:workspace) { Dir.mktmpdir }
310
337
  let(:dr1) { described_class.new(druid_str, workspace) }
311
338
  let(:dr2) { described_class.new(strictly_valid_druid_str, workspace) }
339
+ let(:dr3) { DruidTools::AccessDruid.new(access_druid_str, workspace) }
312
340
  let(:pathname1) { dr1.pathname }
313
341
 
314
342
  before do
@@ -319,6 +347,32 @@ RSpec.describe DruidTools::Druid do
319
347
  FileUtils.remove_entry workspace
320
348
  end
321
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
+
322
376
  context 'when there is a shared ancestor' do
323
377
  before do
324
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.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Klein
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-08-15 00:00:00.000000000 Z
12
+ date: 2022-04-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deprecation
@@ -71,30 +71,30 @@ dependencies:
71
71
  name: rubocop
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - "~>"
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
- version: 0.70.0
76
+ version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - "~>"
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
- version: 0.70.0
83
+ version: '0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rubocop-rspec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - "~>"
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
- version: 1.33.0
90
+ version: '0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - "~>"
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
- version: 1.33.0
97
+ version: '0'
98
98
  description: Tools to manipulate DRUID trees and content directories
99
99
  email:
100
100
  - mbklein@stanford.edu
@@ -102,11 +102,12 @@ executables: []
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".circleci/config.yml"
106
+ - ".github/pull_request_template.md"
105
107
  - ".gitignore"
106
108
  - ".rspec"
107
109
  - ".rubocop.yml"
108
110
  - ".rubocop_todo.yml"
109
- - ".travis.yml"
110
111
  - Gemfile
111
112
  - LICENSE
112
113
  - README.md
@@ -126,7 +127,8 @@ homepage: http://github.com/sul-dlss/druid-tools
126
127
  licenses:
127
128
  - ALv2
128
129
  - Stanford University Libraries
129
- metadata: {}
130
+ metadata:
131
+ rubygems_mfa_required: 'true'
130
132
  post_install_message:
131
133
  rdoc_options: []
132
134
  require_paths:
@@ -135,15 +137,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
137
  requirements:
136
138
  - - ">="
137
139
  - !ruby/object:Gem::Version
138
- version: '0'
140
+ version: '3.0'
139
141
  required_rubygems_version: !ruby/object:Gem::Requirement
140
142
  requirements:
141
143
  - - ">="
142
144
  - !ruby/object:Gem::Version
143
145
  version: '0'
144
146
  requirements: []
145
- rubyforge_project:
146
- rubygems_version: 2.7.6
147
+ rubygems_version: 3.2.32
147
148
  signing_key:
148
149
  specification_version: 4
149
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.