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's sepia_id (from the file/directory name)
  • full_path — absolute path to the object on disk
  • relative_path — path relative to the storage root
  • storage_path — the storage root this resolver was created with

It also provides:

  • container? — true if the path is a directory (a Container object)
  • serializable? — true if the path is a file (a Serializable object)
  • object(klass) — loads and returns the actual object, or nil if 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

These utilities have their own user guide chapters: