Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cbeer/pairtree
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: ruby-microservices/pairtree
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Able to merge. These branches can be automatically merged.

Commits on Jun 9, 2011

  1. Massive, non-atomic refactor.

    * Change from Jeweler gem format to bundler gem format
    * Change from Test::Unit to RSpec
    * More object manipulation from Pairtree::Root (Root#purge!, Root#[], Root#exists?)
    * Much more file manipulation from Pairtree::Obj (Dir and File methods invoked relative to ppath)
    mbklein committed Jun 9, 2011
    Copy the full SHA
    10d0a34 View commit details
  2. Add rcov rake task

    mbklein committed Jun 9, 2011
    Copy the full SHA
    b449346 View commit details
  3. Copy the full SHA
    0ab346d View commit details
  4. Add more tests

    mbklein committed Jun 9, 2011
    Copy the full SHA
    1ea1475 View commit details
  5. 100% spec test coverage

    mbklein committed Jun 9, 2011
    Copy the full SHA
    7e1023a View commit details

Commits on Jun 10, 2011

  1. Replace Pairtree::Client class/object with Pairtree.at(path) factory …

    …method. Pairtree::Root is now the first-class object.
    mbklein committed Jun 10, 2011
    Copy the full SHA
    000f095 View commit details
  2. Copy the full SHA
    5214020 View commit details
  3. Copy the full SHA
    dd1a188 View commit details
  4. Copy the full SHA
    9888e0b View commit details
  5. Copy the full SHA
    3b481d9 View commit details
  6. Copy the full SHA
    fd06df8 View commit details
  7. Add YARD documentation

    mbklein committed Jun 10, 2011
    Copy the full SHA
    770be07 View commit details
  8. Copy the full SHA
    e4aca82 View commit details

Commits on Jun 11, 2011

  1. Copy the full SHA
    0c34c39 View commit details

Commits on Jan 27, 2012

  1. Copy the full SHA
    b169d6c View commit details
  2. add bundler gem tasks

    Chris Beer committed Jan 27, 2012
    Copy the full SHA
    16c3596 View commit details

Commits on Aug 16, 2012

  1. Fixup for ruby 1.8 and 1.9

    cbeer committed Aug 16, 2012
    Copy the full SHA
    f4178b8 View commit details
  2. add rake to gemfile

    cbeer committed Aug 16, 2012
    Copy the full SHA
    7f24ede View commit details
  3. fixup rakefile

    cbeer committed Aug 16, 2012
    Copy the full SHA
    8b8029c View commit details
  4. Copy the full SHA
    cd133a9 View commit details

Commits on May 5, 2015

  1. Copy the full SHA
    c13c545 View commit details
  2. ignore .idea

    malakai97 committed May 5, 2015
    Copy the full SHA
    3bebe3d View commit details
  3. Copy the full SHA
    9743907 View commit details
  4. update gemspec and readme

    malakai97 committed May 5, 2015
    Copy the full SHA
    0e3b980 View commit details
  5. Copy the full SHA
    3e47685 View commit details

Commits on May 17, 2016

  1. Copy the full SHA
    bd87706 View commit details

Commits on Mar 28, 2023

  1. Support for ruby-3.x

    - remove calls to File.exists?
    - use standardrb
    - use simplecov always
    - add github action
    aelkiss committed Mar 28, 2023
    Copy the full SHA
    cb79668 View commit details
  2. run standardrb

    aelkiss committed Mar 28, 2023
    Copy the full SHA
    180866d View commit details
  3. Merge pull request #2 from mlibrary/ruby-3.x

    Support for ruby 3.x; use standardrb
    billdueber authored Mar 28, 2023
    Copy the full SHA
    c971c6c View commit details
  4. Prepare for merge to non-forked version

    * Remove references to rpairtree
    * Remove coveralls upload from action
    * Remove references to Ruby 1.8
    * Remove travis config
    * Update link to spec to point to live URL
    aelkiss committed Mar 28, 2023
    Copy the full SHA
    62de3ff View commit details
  5. Merge pull request #5 from mlibrary/update-upstream

    Updates for current ruby
    aelkiss authored Mar 28, 2023
    Copy the full SHA
    8667d00 View commit details
22 changes: 22 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Tests

on: push

jobs:
test:
runs-on: ubuntu-latest
name: Ruby ${{ matrix.ruby }}
strategy:
matrix:
ruby: [2.7, 3.0, 3.1, 3.2]
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run linter for Ruby
run: bundle exec standardrb
- name: Run tests
run: bundle exec rspec
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ doc

# bundler
.bundle
vendor/

# jeweler generated
pkg
@@ -42,3 +43,5 @@ pkg
#*.swp
#
Gemfile.lock

.idea/
19 changes: 8 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
source "http://rubygems.org"
# Add dependencies required to use your gem here.
# Example:
# gem "activesupport", ">= 2.3.5"
source "https://rubygems.org"

# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
gem "jeweler", "~> 1.5.1"
gem "rcov", ">= 0"
# Specify your gem's dependencies in test.gemspec
gemspec

group :development, :test do
gem "simplecov"
gem "standardrb"
gem "simplecov-lcov"
end
32 changes: 12 additions & 20 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
Copyright (c) 2010 Chris Beer

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
###########################################################################
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[![Tests](https://github.com/ruby-microservices/pairtree/actions/workflows/tests.yml/badge.svg)](https://github.com/ruby-microservices/pairtree/actions/workflows/tests.yml)
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)

# pairtree

Ruby implementation of the [Pairtree](https://www.ietf.org/archive/id/draft-kunze-pairtree-01.txt) specification from the California Digital Library.

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'pairtree'
```

And then execute:

$ bundle

Or install it yourself as:

$ gem install pairtree

## Usage

```ruby
require 'pairtree'

# Initiate a tree
pairtree = Pairtree.at('./data', :prefix => 'pfx:', :create => true)

# Create a ppath
obj = pairtree.mk('pfx:abc123def')

# Access an existing ppath
obj = pairtree['pfx:abc123def']
obj = pairtree.get('pfx:abc123def')

# ppaths are Dir instances with some File and Dir class methods mixed in
obj.read('content.xml')
=> "<content/>"
obj.open('my_file.txt','w') { |io| io.write("Write text to file") }
obj.entries
=> ["content.xml","my_file.txt"]
obj['*.xml']
=> ["content.xml"]
obj.each { |file| ... }
obj.unlink('my_file.txt')

# Delete a ppath and all its contents
pairtree.purge!('pfx:abc123def')
```

## Copyright

Copyright (c) 2010 Chris Beer. See LICENSE.txt for further details.
19 changes: 0 additions & 19 deletions README.rdoc

This file was deleted.

67 changes: 26 additions & 41 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,37 @@
require 'rubygems'
require 'bundler'
require "rubygems"
require "bundler"
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
warn e.message
warn "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'

require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "pairtree"
gem.homepage = "http://github.com/cbeer/pairtree"
gem.license = "MIT"
gem.summary = %Q{Ruby Pairtree implementation}
gem.email = "chris@cbeer.info"
gem.authors = ["Chris Beer"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new
Bundler::GemHelper.install_tasks

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
require "rake"
require "rspec"
require "rspec/core/rake_task"

require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
desc "Default: run specs."
task default: :spec

task :default => :test

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
# Use yard to build docs
begin
require "yard"
require "yard/rake/yardoc_task"
project_root = __dir__
doc_destination = File.join(project_root, "doc")

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "pairtree #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
YARD::Rake::YardocTask.new(:doc) do |yt|
yt.files = Dir.glob(File.join(project_root, "lib", "**", "*.rb")) +
[File.join(project_root, "README.md")]
yt.options = ["--output-dir", doc_destination, "--readme", "README.md"]
end
rescue LoadError
desc "Generate YARD Documentation"
task :doc do
abort "Please install the YARD gem to generate rdoc."
end
end
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

86 changes: 81 additions & 5 deletions lib/pairtree.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,83 @@
require 'pairtree/identifier'
require 'pairtree/path'
require 'pairtree/obj'
require 'pairtree/root'
require 'pairtree/client'
require "pairtree/identifier"
require "pairtree/path"
require "pairtree/obj"
require "pairtree/root"

require "fileutils"

module Pairtree
class IdentifierError < RuntimeError; end

class PathError < RuntimeError; end

class VersionMismatch < RuntimeError; end

SPEC_VERSION = 0.1

##
# Instantiate a pairtree at a given path location
# @param [String] path The path in which the pairtree resides
# @param [Hash] args Pairtree options
# @option args [String] :prefix (nil) the identifier prefix used throughout the pairtree
# @option args [String] :version (Pairtree::SPEC_VERSION) the version of the pairtree spec that this tree conforms to
# @option args [Boolean] :create (false) if true, create the pairtree and its directory structure if it doesn't already exist
def self.at path, args = {}
args = {prefix: nil, version: nil, create: false}.merge(args)
args[:version] ||= SPEC_VERSION
args[:version] = args[:version].to_f

root_path = File.join(path, "pairtree_root")
prefix_file = File.join(path, "pairtree_prefix")
version_file = File.join(path, pairtree_version_filename(args[:version]))
existing_version_file = Dir[File.join(path, "pairtree_version*")].max

if args.delete(:create)
if File.exist?(path) && !File.directory?(path)
raise PathError, "#{path} exists, but is not a valid pairtree root"
end
FileUtils.mkdir_p(root_path)

unless File.exist? prefix_file
File.write(prefix_file, args[:prefix].to_s)
end

if existing_version_file
if existing_version_file != version_file
stored_version = existing_version_file.scan(/([0-9]+)_([0-9]+)/).flatten.join(".").to_f
raise VersionMismatch, "Version #{args[:version]} specified, but #{stored_version} found."
end
else
args[:version] ||= SPEC_VERSION
version_file = File.join(path, pairtree_version_filename(args[:version]))
File.write(version_file, %(This directory conforms to Pairtree Version #{args[:version]}. Updated spec: http://www.cdlib.org/inside/diglib/pairtree/pairtreespec.html))
existing_version_file = version_file
end
else
unless File.directory? root_path
raise PathError, "#{path} does not point to an existing pairtree"
end
end

stored_prefix = File.read(prefix_file)
unless args[:prefix].nil? || (args[:prefix].to_s == stored_prefix)
raise IdentifierError, "Specified prefix #{args[:prefix].inspect} does not match stored prefix #{stored_prefix.inspect}"
end
args[:prefix] = stored_prefix

stored_version = existing_version_file.scan(/([0-9]+)_([0-9]+)/).flatten.join(".").to_f
args[:version] ||= stored_version
unless args[:version] == stored_version
raise VersionMismatch, "Version #{args[:version]} specified, but #{stored_version} found."
end

Pairtree::Root.new(File.join(path, "pairtree_root"), args)
end

class << self
private

def pairtree_version_filename(version)
"pairtree_version#{version.to_s.tr(".", "_")}"
end
end
end
18 changes: 0 additions & 18 deletions lib/pairtree/client.rb

This file was deleted.

Loading