Skip to content

Commit

Permalink
Deprecate rmdir, prune! and prune_ancestors
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Aug 15, 2019
1 parent 92ea588 commit 7cfbc7f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 1 addition & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
source 'https://rubygems.org'

group :development do
gem 'debugger', platform: :ruby_19
gem 'pry-debugger', platform: :ruby_19
gem 'rcov', platform: :ruby_18
gem 'ruby-debug', platform: :ruby_18
gem 'simplecov', platform: %i[ruby_19 ruby_20]
gem 'byebug'
end

gemspec
1 change: 1 addition & 0 deletions druid-tools.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.version = File.read('VERSION').strip

gem.add_dependency 'deprecation'
gem.add_development_dependency 'coveralls'
gem.add_development_dependency 'rake', '>= 10.1.0'
gem.add_development_dependency 'rspec', '~> 3.0'
Expand Down
8 changes: 8 additions & 0 deletions lib/druid_tools/druid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

require 'pathname'
require 'fileutils'
require 'deprecation'

module DruidTools
class Druid
extend Deprecation
self.deprecation_horizon = 'druid-tools 3.0.0'

attr_accessor :druid, :base

# See https://consul.stanford.edu/pages/viewpage.action?title=SURI+2.0+Specification&spaceKey=chimera
Expand Down Expand Up @@ -122,6 +126,7 @@ def mkdir_with_final_link(source, extra = nil)
FileUtils.mkdir_p(real_path)
FileUtils.ln_s(source, new_path, force: true)
end
deprecation_deprecate :mkdir_with_final_link

def rmdir(extra = nil)
parts = tree
Expand All @@ -137,6 +142,7 @@ def rmdir(extra = nil)
parts.pop
end
end
deprecation_deprecate :rmdir

def pathname
Pathname path
Expand All @@ -152,6 +158,7 @@ def prune!
parent.rmtree if parent.exist? && parent != base_pathname
prune_ancestors parent.parent
end
deprecation_deprecate :prune!

# @param [Pathname] outermost_branch The branch at which pruning begins
# @return [void] Ascend the druid tree and prune empty branches
Expand All @@ -162,5 +169,6 @@ def prune_ancestors(outermost_branch)
break if outermost_branch == base_pathname
end
end
deprecation_deprecate :prune_ancestors
end
end
10 changes: 10 additions & 0 deletions spec/druid_tools_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
end

it '#mkdir, #rmdir create and destroy druid directories' do
allow(Deprecation).to receive(:warn)
expect(File.exist?(tree1)).to eq false
expect(File.exist?(tree2)).to eq false

Expand Down Expand Up @@ -259,6 +260,10 @@
end

describe '#mkdir error handling' do
before do
allow(Deprecation).to receive(:warn)
end

it 'raises SameContentExistsError if the directory already exists' do
druid_obj = described_class.new(strictly_valid_druid_str, fixture_dir)
druid_obj.mkdir
Expand All @@ -279,6 +284,7 @@
let(:druid_obj) { described_class.new(strictly_valid_druid_str, fixture_dir) }

before do
allow(Deprecation).to receive(:warn)
FileUtils.mkdir_p(source_dir)
end

Expand Down Expand Up @@ -306,6 +312,10 @@
let(:dr2) { described_class.new(strictly_valid_druid_str, workspace) }
let(:pathname1) { dr1.pathname }

before do
allow(Deprecation).to receive(:warn)
end

after do
FileUtils.remove_entry workspace
end
Expand Down

0 comments on commit 7cfbc7f

Please sign in to comment.