class Shrine::Storage::FileSystem

Defined in:

shrine/storage/file_system.cr

Constant Summary

DEFAULT_DIRECTORY_PERMISSIONS = 493
DEFAULT_PERMISSIONS = 420

Constructors

Instance Method Summary

Instance methods inherited from class Shrine::Storage::Base

clean(path : String) clean, clean? : Bool clean?, delete(id : String) delete, exists?(id : String) : Bool exists?, open(id : String, **options) : IO open, upload(io : IO | UploadedFile, id : String, move = false, **options) upload, url(id : String, **options) : String url

Constructor Detail

def self.new(directory : String, prefix : String | Nil = nil, clean = true, permissions : Int = DEFAULT_PERMISSIONS, directory_permissions : Int = DEFAULT_DIRECTORY_PERMISSIONS) #

Initializes a storage for uploading to the filesystem.

:prefix : The directory relative to #directory to which files will be stored, and it is included in the URL.

:permissions : The UNIX permissions applied to created files. Can be set to nil, in which case the default permissions will be applied. Defaults to 0644.

:directory_permissions : The UNIX permissions applied to created directories. Can be set to nil, in which case the default permissions will be applied. Defaults to 0755.

:clean : By default empty folders inside the directory are automatically deleted, but if it happens that it causes too much load on the filesystem, you can set this option to false.


[View source]

Instance Method Detail

def delete(id : String) #

Deletes the file, and by default deletes the containing directory if it's empty.


[View source]
def directory : String #

[View source]
def directory_permissions : Int32 #

[View source]
def exists?(id : String) : Bool #

Returns true if the file exists on the filesystem.


[View source]
def expanded_directory : String #

[View source]
def open(id : String, **options) : File #

Opens the file on the given location in read mode. Accepts additional File.open arguments.


[View source]
def path(id : String) : String #

Returns the full path to the file.


[View source]
def permissions : Int32 #

[View source]
def prefix : String | Nil #

[View source]
def upload(io : IO | UploadedFile, id : String, move = false, **options) #

Copies the file into the given location.


[View source]
def url(id : String, host : String | Nil = nil, **options) : String #

If #relative_prefix is not present, returns a path composed of #directory and the given id. If #relative_prefix is present, it excludes the #directory part from the returned path (e.g. #directory can be set to "public" folder). Both cases accept a :host value which will be prefixed to the generated path. def url(id, host : String? = nil, **options)


[View source]