Utilities
Besides the core modules and storage backends, Sepia ships a few utility classes.
PathResolver
Sepia::PathResolver maps file system paths back to Sepia objects. It is mainly used by the file system watcher, but it's handy for any tool that needs to translate a path like /data/MyDocument/uuid-123 into object information.
resolver = Sepia::PathResolver.new("/data")
if info = resolver.resolve_path("/data/MyDocument/uuid-123")
info.class_name # => "MyDocument"
info.object_id # => "uuid-123"
info.full_path # => "/data/MyDocument/uuid-123"
end
ObjectInfo
resolve_path returns a PathResolver::ObjectInfo struct with:
class_name— the object's class name (from the directory name)object_id— the object'ssepia_id(from the file/directory name)full_path— absolute path to the object on diskrelative_path— path relative to the storage rootstorage_path— the storage root this resolver was created with
It also provides:
container?— true if the path is a directory (aContainerobject)serializable?— true if the path is a file (aSerializableobject)object(klass)— loads and returns the actual object, ornilif loading fails
if info = resolver.resolve_path(path)
if doc = info.object(Document)
puts "Loaded #{doc.class.name} with ID #{doc.sepia_id}"
end
end
Related Modules
These utilities have their own user guide chapters:
- EventLogger — Event Logging
- Backup — Backup and Restore
- Watcher — File System Watching