class Shrine::Storage::FileSystem
- Shrine::Storage::FileSystem
- Shrine::Storage::Base
- Reference
- Object
Defined in:
shrine/storage/file_system.crConstant Summary
-
DEFAULT_DIRECTORY_PERMISSIONS =
493
-
DEFAULT_PERMISSIONS =
420
Constructors
-
.new(directory : String, prefix : String? = nil, clean = true, permissions : Int = DEFAULT_PERMISSIONS, directory_permissions : Int = DEFAULT_DIRECTORY_PERMISSIONS)
Initializes a storage for uploading to the filesystem.
Instance Method Summary
-
#delete(id : String)
Deletes the file, and by default deletes the containing directory if it's empty.
- #directory : String
- #directory_permissions : Int32
-
#exists?(id : String) : Bool
Returns true if the file exists on the filesystem.
- #expanded_directory : String
-
#open(id : String, **options) : File
Opens the file on the given location in read mode.
-
#path(id : String) : String
Returns the full path to the file.
- #permissions : Int32
- #prefix : String?
-
#upload(io : IO | UploadedFile, id : String, move = false, **options)
Copies the file into the given location.
-
#url(id : String, host : String? = nil, **options) : String
If #relative_prefix is not present, returns a path composed of #directory and the given
id
.
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
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
.
Instance Method Detail
Deletes the file, and by default deletes the containing directory if it's empty.
Opens the file on the given location in read mode. Accepts additional
File.open
arguments.
Copies the file into the given location.
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)