Skip to content

Commit 8a75aea

Browse files
committed
Add standardrb
1 parent 3e58c4d commit 8a75aea

File tree

6 files changed

+44
-58
lines changed

6 files changed

+44
-58
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source "https://rubygems.org"
22

3-
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
44

55
# Specify your gem's dependencies in ht-pairtree.gemspec
66
gemspec

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ require "rspec/core/rake_task"
33

44
RSpec::Core::RakeTask.new(:spec)
55

6-
task :default => :spec
6+
task default: :spec

ht-pairtree.gemspec

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,44 @@
1-
21
lib = File.expand_path("../lib", __FILE__)
32
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
43
require "ht/pairtree/version"
54

65
Gem::Specification.new do |spec|
7-
spec.name = "ht-pairtree"
8-
spec.version = HathiTrust::Pairtree::VERSION
9-
spec.authors = ["Bill Dueber"]
10-
spec.email = ["[email protected]"]
11-
#
12-
spec.summary = %q{Pairtree with extra sugar for the HathiTrust environment}
6+
spec.name = "ht-pairtree"
7+
spec.version = HathiTrust::Pairtree::VERSION
8+
spec.authors = ["Bill Dueber"]
9+
spec.email = ["[email protected]"]
10+
spec.summary = "Pairtree with extra sugar for the HathiTrust environment"
1311
# spec.description = %q{TODO: Write a longer description or delete this line.}
14-
spec.homepage = "https://github.com/hathitrust/ht-pairtree"
15-
spec.license = "MIT"
12+
spec.homepage = "https://github.com/hathitrust/ht-pairtree"
13+
spec.license = "MIT"
1614
#
1715
# # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
1816
# # to allow pushing to a single host or delete this section to allow pushing to any host.
1917
if spec.respond_to?(:metadata)
2018
spec.metadata["allowed_push_host"] = "https://gems.www.lib.umich.edu"
2119
spec.metadata["homepage_uri"] = spec.homepage
2220
spec.metadata["source_code_uri"] = spec.homepage
23-
spec.metadata["changelog_uri"] = spec.homepage + '/CHANGELOG.md'
21+
spec.metadata["changelog_uri"] = spec.homepage + "/CHANGELOG.md"
2422
else
2523
raise "RubyGems 2.0 or newer is required to protect against " \
2624
"public gem pushes."
2725
end
2826

2927
# Specify which files should be added to the gem when it is released.
3028
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
31-
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
3230
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
3331
end
34-
spec.bindir = "exe"
35-
spec.executables = %w[htdir]
32+
spec.bindir = "exe"
33+
spec.executables = %w[htdir]
3634
spec.require_paths = ["lib"]
3735

3836
# The 'pairtree' gem seems to be abandoned. Use the mlibrary
3937
# clone
40-
spec.add_dependency 'rpairtree'
41-
38+
spec.add_dependency "rpairtree"
4239

4340
spec.add_development_dependency "bundler", "~> 2.0"
4441
spec.add_development_dependency "rake", "~> 12.0"
4542
spec.add_development_dependency "rspec", "~> 3.0"
43+
spec.add_development_dependency "standardrb"
4644
end

lib/ht/pairtree.rb

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1-
# coding: utf-8
21
require "ht/pairtree/version"
32

43
# Pairtree is ancient and throws warnings so we suppress them on require
54
oldverbose = $VERBOSE
65
$VERBOSE = nil
7-
require 'pairtree'
6+
require "pairtree"
87
$VERBOSE = oldverbose
98

10-
require 'fileutils'
9+
require "fileutils"
1110

1211
module HathiTrust
1312
# A simple Pairtree implementation to make it easier to work with
1413
# the HathiTrust pairtree structure.
1514
class Pairtree
16-
17-
class PairtreeError < StandardError;
15+
class PairtreeError < StandardError
1816
end
1917

2018
class NamespaceDoesNotExist < PairtreeError
2119
end
2220

23-
SDR_DATA_ROOT_DEFAULT = (ENV["SDRDATAROOT"] || '/sdr1') + '/obj'
21+
SDR_DATA_ROOT_DEFAULT = (ENV["SDRDATAROOT"] || "/sdr1") + "/obj"
2422

2523
# Create a new pairtree object rooted at the given directory
2624
# @param [String] root The root of the über-pairtree (takes `ENV['SDRDATAROOT'] + 'obj'` by default)
2725
def initialize(root: SDR_DATA_ROOT_DEFAULT)
2826
@root = Pathname.new(root)
2927
end
3028

31-
32-
3329
# Get a Pathname object corresponding to the directory holding data for the given HTID
3430
# @param [String] htid The HathiTrust ID for an object
3531
# @return [Pathname] Path to the given object's directory
@@ -40,7 +36,6 @@ def path_for(htid)
4036
alias_method :dir, :path_for
4137
alias_method :path_to, :path_for
4238

43-
4439
# Get the underlying pairtree for the given obj.
4540
# @param [String] htid The HathiTrust ID for an object
4641
# @return [Pairtree] the pairtree for that object
@@ -69,29 +64,26 @@ def namespace_exists?(htid)
6964
namespace_dir(htid).exist?
7065
end
7166

72-
7367
def create_namespace_dir(htid)
7468
ndir = namespace_dir(htid)
75-
return self if Dir.exists?(ndir)
69+
return self if Dir.exist?(ndir)
7670
Dir.mkdir(ndir)
77-
File.open(ndir + "pairtree_prefix", 'w:utf-8') {|f| f.print namespace(htid)}
78-
File.open(ndir + "pairtree_version0_1", 'w:utf-8') {|f| }
71+
File.open(ndir + "pairtree_prefix", "w:utf-8") { |f| f.print namespace(htid) }
72+
File.open(ndir + "pairtree_version0_1", "w:utf-8") { |f| }
7973
Dir.mkdir(ndir + "pairtree_root")
80-
return self
74+
self
8175
end
8276

83-
8477
def namespace_dir(htid)
8578
@root + namespace(htid)
8679
end
8780

8881
def namespace(htid)
89-
htid.split('.', 2).first
82+
htid.split(".", 2).first
9083
end
9184

9285
def pairtree_root(htid)
9386
::Pairtree.at(namespace_dir(htid))
9487
end
95-
9688
end
9789
end

lib/ht/pairtree/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module HathiTrust
2-
class Pairtree
2+
class Pairtree
33
VERSION = "0.1.0"
44
end
55
end

spec/ht/pairtree_spec.rb

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
require 'pairtree'
2-
require 'fileutils'
3-
require 'tmpdir'
4-
1+
require "pairtree"
2+
require "fileutils"
3+
require "tmpdir"
54

65
RSpec.describe HathiTrust::Pairtree do
7-
86
let(:idmap) do
97
{
10-
'uc1.c3292592' => 'sdr1/obj/uc1/pairtree_root/c3/29/25/92/c3292592',
11-
'loc.ark:/13960/t9w09k00s' => 'sdr1/obj/loc/pairtree_root/ar/k+/=1/39/60/=t/9w/09/k0/0s/ark+=13960=t9w09k00s',
12-
'ia.ark:/13960/t9w10cs7x' => 'sdr1/obj/ia/pairtree_root/ar/k+/=1/39/60/=t/9w/10/cs/7x/ark+=13960=t9w10cs7x'
8+
"uc1.c3292592" => "sdr1/obj/uc1/pairtree_root/c3/29/25/92/c3292592",
9+
"loc.ark:/13960/t9w09k00s" => "sdr1/obj/loc/pairtree_root/ar/k+/=1/39/60/=t/9w/09/k0/0s/ark+=13960=t9w09k00s",
10+
"ia.ark:/13960/t9w10cs7x" => "sdr1/obj/ia/pairtree_root/ar/k+/=1/39/60/=t/9w/10/cs/7x/ark+=13960=t9w10cs7x"
1311
}
1412
end
1513

1614
def make_paths(idmap)
1715
idmap.values.each do |subdir|
1816
dir = @tmpdir + subdir
1917
FileUtils.mkdir_p(dir)
20-
root = @tmpdir + Pathname.new(subdir.split('/')[0..2].join('/'))
21-
prefix = subdir.split('/')[2]
22-
File.open(root + 'pairtree_prefix', 'w:utf-8') do |pp|
23-
pp.print(prefix + '.')
18+
root = @tmpdir + Pathname.new(subdir.split("/")[0..2].join("/"))
19+
prefix = subdir.split("/")[2]
20+
File.open(root + "pairtree_prefix", "w:utf-8") do |pp|
21+
pp.print(prefix + ".")
2422
end
25-
File.open(root + 'pairtree_version0_1', 'w:utf-8') {}
23+
File.open(root + "pairtree_version0_1", "w:utf-8") {}
2624
end
2725
end
2826

@@ -40,31 +38,29 @@ def make_paths(idmap)
4038

4139
it "translates names into directories" do
4240
make_paths(idmap)
43-
pt = HathiTrust::Pairtree.new(root: @tmpdir + 'sdr1/obj')
41+
pt = HathiTrust::Pairtree.new(root: @tmpdir + "sdr1/obj")
4442

4543
idmap.each_pair do |id, dir|
4644
expect(pt.path_for(id).to_s).to eq((@tmpdir + dir).to_s)
4745
end
4846
end
4947

5048
describe "#create" do
51-
let(:pt) { HathiTrust::Pairtree.new(root: @tmpdir + 'sdr1/obj') }
49+
let(:pt) { HathiTrust::Pairtree.new(root: @tmpdir + "sdr1/obj") }
5250

5351
it "can create new object directories" do
54-
expect {pt.create('test.something', new_namespace_allowed: false)}.to raise_error(HathiTrust::Pairtree::NamespaceDoesNotExist)
55-
expect(pt.create('test.something', new_namespace_allowed: true).exists?('.')).to be true
52+
expect { pt.create("test.something", new_namespace_allowed: false) }.to raise_error(HathiTrust::Pairtree::NamespaceDoesNotExist)
53+
expect(pt.create("test.something", new_namespace_allowed: true).exists?(".")).to be true
5654
end
5755

5856
it "create is idempotent" do
59-
pt.create('test.something', new_namespace_allowed: true)
60-
expect(pt.create('test.something').exists?('.')).to be true
57+
pt.create("test.something", new_namespace_allowed: true)
58+
expect(pt.create("test.something").exists?(".")).to be true
6159
end
6260

6361
it "new_namespace_allowed is idempotent" do
64-
pt.create('test.something', new_namespace_allowed: true)
65-
expect(pt.create('test.somethingelse', new_namespace_allowed: true).exists?('.')).to be true
62+
pt.create("test.something", new_namespace_allowed: true)
63+
expect(pt.create("test.somethingelse", new_namespace_allowed: true).exists?(".")).to be true
6664
end
6765
end
68-
69-
7066
end

0 commit comments

Comments
 (0)