abstract class Avram::SaveOperation(T)

Included Modules

Defined in:

avram/save_operation.cr

Constant Summary

ATTRIBUTES = [] of Nil
OPERATION_NEEDS = [] of Nil

Constructors

Class Method Summary

Instance Method Summary

Macro Summary

Instance methods inherited from module Avram::MarkAsFailed

mark_as_failed mark_as_failed

Instance methods inherited from module Avram::NestedSaveOperation

mark_nested_save_operations_as_failed mark_nested_save_operations_as_failed, nested_save_operations nested_save_operations

Instance methods inherited from module Avram::OperationErrors

add_error(key : Symbol, message : String) : Nil add_error, errors : Hash(Symbol, Array(String)) errors

Instance methods inherited from module Avram::Validations

validate_acceptance_of(attribute : Avram::Attribute(Bool), message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_acceptance_of)) : Bool validate_acceptance_of, validate_at_most_one_filled(*attributes, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_at_most_one_filled)) : Bool validate_at_most_one_filled, validate_confirmation_of(attribute : Avram::Attribute(T), with confirmation_attribute : Avram::Attribute(T), message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_confirmation_of)) : Bool forall T validate_confirmation_of, validate_exactly_one_filled(*attributes, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_exactly_one_filled)) : Bool validate_exactly_one_filled, validate_format_of(attribute : Avram::Attribute(String), with regex : Regex, match : Bool = true, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_format_of), allow_nil : Bool = false) : Bool validate_format_of, validate_inclusion_of(attribute : Avram::Attribute(T), in allowed_values : Enumerable(T), message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_inclusion_of), allow_nil : Bool = false) : Bool forall T validate_inclusion_of, validate_numeric(attribute : Avram::Attribute(Number), greater_than = nil, less_than = nil, message = nil, allow_nil : Bool = false) : Bool
validate_numeric(attribute : Avram::Attribute(Number), *, at_least = nil, no_more_than = nil, message = nil, allow_nil : Bool = false) : Bool
validate_numeric
, validate_required(*attributes, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_required)) : Bool validate_required, validate_size_of(attribute : Avram::Attribute(String) | Avram::Attribute(Array(T)), min : Number | Nil = nil, max : Number | Nil = nil, message : Avram::Attribute::ErrorMessage | Nil = nil, allow_nil : Bool = false) : Bool forall T
validate_size_of(attribute : Avram::Attribute(String) | Avram::Attribute(Array(T)), *, is exact_size : Number, message : Avram::Attribute::ErrorMessage = Avram.settings.i18n_backend.get(:validate_exact_size_of), allow_nil : Bool = false) : Bool forall T
validate_size_of

Instance methods inherited from module Avram::DefineAttribute

attributes attributes

Instance methods inherited from class Object

blank_for_validates_required? : Bool blank_for_validates_required?

Constructor Detail

def self.new(params : Avram::Paramable) #

[View source]
def self.new #

[View source]

Class Method Detail

def self.import(all_operations : Array(self)) #

def self.param_key #

[View source]
def self.upsert(*args, **named_args) #

Performs a create or update depending on if there is a conflicting row in the database.

See Avram::Upsert.upsert_lookup_columns for full documentation and examples.


[View source]
def self.upsert!(*args, **named_args) #

Performs a create or update depending on if there is a conflicting row in the database.

See Avram::Upsert.upsert_lookup_columns for full documentation and examples.


[View source]

Instance Method Detail

def after_commit(_record : T) #

[View source]
def after_save(_record : T) #

[View source]
abstract def attributes #

[View source]
def before_save #

[View source]
def changes : Hash(Symbol, String | Nil) #

[View source]
def created? #

[View source]
def custom_errors #

def database(*args, **options) #

[View source]
def database(*args, **options, &) #

[View source]
def generic_attributes #

[View source]
def new_record? : Bool #

#persisted? always returns true in after_* hooks, whether a new record was created, or an existing one was updated.

This method should always return true for a create or false for an update, independent of the stage we are at in the operation.


[View source]
def params #

[View source]
def persisted? : Bool #

[View source]
def primary_key_name(*args, **options) #

[View source]
def primary_key_name(*args, **options, &) #

[View source]
def record #

[View source]
def run_default_validations #

Runs all required validations for required types as well as any additional valitaions the type needs to run e.g. polymorphic validations


[View source]
def save : Bool #

[View source]
def save! : T #

[View source]
def save_failed? #

Return true if the operation has run and the record failed to save


[View source]
def save_status : OperationStatus #

[View source]
def save_status=(save_status : OperationStatus) #

[View source]
def saved? #

Returns true if the operation has run and saved the record successfully


[View source]
def table_name(*args, **options) #

[View source]
def table_name(*args, **options, &) #

[View source]
def update! : T #

[View source]
def updated? #

[View source]
def valid? : Bool #

Runs required validation, then returns true if all attributes are valid, and there's no custom errors


[View source]
def values : Hash(Symbol, String | Nil) #

[View source]

Macro Detail

macro add_cast_value_methods(columns) #

[View source]
macro param_key(key) #

macro permit_columns(*attribute_names) #

[View source]
macro skip_default_validations #

This allows you to skip the default validations which may be used as an escape hatch when you want to allow storing an empty string value.


[View source]