class Marten::DB::Field::File

Overview

Represents a file field's value.

Instances of this class give access to the properties of a file manipulated by a file field. They allow to read a file's content, and to attach new files to model records.

Defined in:

marten/db/field.cr
marten/db/field/file.cr
marten/db/field/file/file.cr

Constructors

Instance Method Summary

Instance methods inherited from class Marten::DB::Field::Base

blank? : Bool blank?, db_column db_column, db_column! : ::String db_column!, db_column? db_column?, default default, from_db(value) from_db, from_db_result_set(result_set : ::DB::ResultSet) from_db_result_set, id : String id, index? : Bool index?, null? : Bool null?, prepare_save(record, new_record = false) prepare_save, primary_key? : Bool primary_key?, related_model related_model, relation? relation?, relation_name relation_name, to_column : Management::Column::Base | Nil to_column, to_db(value) : ::DB::Any to_db, unique? : Bool unique?, validate(record, value) validate

Constructor methods inherited from class Marten::DB::Field::Base

new(id : ::String, primary_key : ::Bool = false, blank : ::Bool = false, null : ::Bool = false, unique : ::Bool = false, index : ::Bool = false, db_column : ::String | Symbol | Nil = nil) new

Constructor Detail

def self.new(id : ::String, storage : Core::Storage::Base | Nil = nil, max_size : Int32 = 100, default : ::String | Nil = nil, upload_to : Proc(::String, ::String) | ::String = "", blank = false, null = false, unique = false, index = false, db_column = nil) #

[View source]

Instance Method Detail

def default : String? #
Description copied from class Marten::DB::Field::Base

Returns the default value of the field if any.


[View source]
def empty_value?(value) : ::Bool #

[View source]
def from_db(value) : Marten::DB::Field::File::File | Nil #
Description copied from class Marten::DB::Field::Base

Converts the raw DB value to the corresponding field value.


[View source]
def from_db_result_set(result_set : ::DB::ResultSet) : Marten::DB::Field::File::File | Nil #
Description copied from class Marten::DB::Field::Base

Extracts the field value from a DB result set and returns the right object corresponding to this value.


[View source]
def max_size : Int32 #

Returns the max size of the string corresponding to the file path to be stored in the database.


[View source]
def prepare_save(record, new_record = false) #
Description copied from class Marten::DB::Field::Base

Runs pre-save logic for the specific field and record at hand.

This method does nothing by default but can be overridden for specific fields that need to set values on the model instance before save or perform any pre-save logic.


[View source]
def sanitize_filename(filename : ::String) : ::String #

[View source]
def storage #

Returns the storage object that should be used to store the file.


[View source]
def to_column : Management::Column::Base | Nil #
Description copied from class Marten::DB::Field::Base

Returns a migration column object corresponding to the field at hand.


[View source]
def to_db(value) : ::DB::Any #
Description copied from class Marten::DB::Field::Base

Converts the field value to the corresponding DB value.


[View source]
def upload_to : String -> String | String #

Returns the path where the file should be stored or a proc returning this path.


[View source]