class Sepia::PathResolver

Overview

Utility class for resolving file system paths to Sepia objects

This helper provides methods to convert file system paths back to Sepia objects, which is particularly useful for file system watchers and other tools that need to map file paths back to object instances.

Example

# Given a file path like "/data/MyDocument/uuid-123"
resolver = Sepia::PathResolver.new("/data")

info = resolver.resolve_path("/data/MyDocument/uuid-123")
info.class_name # => "MyDocument"
info.object_id  # => "uuid-123"
info.full_path  # => "/data/MyDocument/uuid-123"

Defined in:

sepia/path_resolver.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(storage_path : String) #

Creates a new PathResolver

resolver = PathResolver.new("/data/sepia")
resolver = PathResolver.new(Sepia::Storage.instance.path)

[View source]

Instance Method Detail

def list_all_objects : Array(ObjectInfo) #

List all Sepia objects in the storage directory

Returns an array of ObjectInfo for all found objects

resolver = PathResolver.new("/data")
objects = resolver.list_all_objects
objects.each do |info|
  puts "#{info.class_name}: #{info.object_id}"
end

[View source]
def resolve_and_load(full_path : String, klass : Class) : Object | Nil #

Resolve a path and load the actual Sepia object

This is a convenience method that combines resolve_path and object loading

obj = resolver.resolve_and_load("/data/MyDocument/uuid-123", TestDocument)
if obj
  puts "Loaded: #{obj.class.name} (#{obj.sepia_id})"
end

[View source]
def resolve_path(full_path : String) : ObjectInfo | Nil #

Resolve a file system path to Sepia object information

info = resolver.resolve_path("/data/MyDocument/uuid-123")
info.class_name # => "MyDocument"
info.object_id  # => "uuid-123"

[View source]
def storage_path : String #

Base storage path for resolving objects


[View source]
def storage_path=(storage_path : String) #

Base storage path for resolving objects


[View source]
def valid_sepia_path?(path : String) : Bool #

Check if a path is a valid Sepia object path

if resolver.valid_sepia_path?("/data/MyDocument/uuid-123")
  puts "This is a valid Sepia object path"
end

[View source]