-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Files should be independent of the ActiveFedora::Base object.
This enables files to be created and saved without a container.
- Loading branch information
Showing
34 changed files
with
263 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ActiveFedora | ||
class FilePathBuilder | ||
# Builds a relative path for a file | ||
def self.build(digital_object, name, prefix) | ||
name = nil if name == '' | ||
prefix ||= 'DS' | ||
name || generate_dsid(digital_object, prefix) | ||
end | ||
|
||
# return a valid dsid that is not currently in use. Uses a prefix (default "DS") and an auto-incrementing integer | ||
# Example: if there are already datastreams with IDs DS1 and DS2, this method will return DS3. If you specify FOO as the prefix, it will return FOO1. | ||
def self.generate_dsid(digital_object, prefix) | ||
return unless digital_object | ||
matches = digital_object.attached_files.keys.map {|d| data = /^#{prefix}(\d+)$/.match(d); data && data[1].to_i}.compact | ||
val = matches.empty? ? 1 : matches.max + 1 | ||
format_dsid(prefix, val) | ||
end | ||
|
||
### Provided so that an application can override how generated ids are formatted (e.g DS01 instead of DS1) | ||
def self.format_dsid(prefix, suffix) | ||
sprintf("%s%i", prefix,suffix) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
dccebd0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor stuff, but I'm all 👍