Skip to content

Commit

Permalink
Add ActiveFedora.fedora.init_base_path
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Dec 2, 2014
1 parent 86cb558 commit 2ba3f2e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 2 additions & 6 deletions lib/active_fedora/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.tombstone_path
end

def self.root_resource_path
ActiveFedora.fedora.base_path.sub('/', '')
ActiveFedora.fedora.root_resource_path
end

def self.connection
Expand All @@ -48,11 +48,7 @@ def self.cleanout_solr
end

def self.reinitialize_repo
begin
ActiveFedora.fedora.connection.put(root_resource_path, "")
rescue Ldp::HttpError => exception
log "#reinitialize_repo in spec_helper.rb raised #{exception}"
end
ActiveFedora.fedora.init_base_path
end

def self.log(message)
Expand Down
18 changes: 18 additions & 0 deletions lib/active_fedora/fedora.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,23 @@ def base_path
def connection
@connection ||= Ldp::Client.new(host)
end

SLASH = '/'.freeze
BLANK = ''.freeze

# Call this to create a Container Resource to act as the base path for this connection
def init_base_path
connection.get(root_resource_path)
ActiveFedora::Base.logger.warn "Attempted to init `#{root_resource_path}`, but it already exists" if ActiveFedora::Base.logger
return false
rescue Ldp::NotFound
connection.put(root_resource_path, BLANK).success?
end

# Remove a leading slash from the base_path
def root_resource_path
@root_resource_path ||= base_path.sub(SLASH, BLANK)
end

end
end

0 comments on commit 2ba3f2e

Please sign in to comment.