abstract struct DynFork::Model

Overview

Abstraction for converting Crystal structures into DynFork Models.

Simple example:

@[DynFork::Meta(service_name: "Accounts")]
struct User < DynFork::Model
  getter username = DynFork::Fields::TextField.new
  getter birthday = DynFork::Fields::DateField.new
end

Extended example:

@[DynFork::Meta(
  service_name: "Accounts",
  delete_doc?: false,
)]
struct User < DynFork::Model
  getter username = DynFork::Fields::TextField.new(
    label: "Username",
    maxlength: 150,
    minlength: 1,
    regex: "^[a-zA-Z0-9_@.+]$",
    regex_err_msg: "Allowed chars: a-z A-Z 0-9 _ @ . +",
    required: true,
    unique: true
  )
  getter email = DynFork::Fields::EmailField.new(
    label: "E-mail",
    maxlength: 320,
    required: true,
    unique: true
  )
  getter birthday = DynFork::Fields::DateField.new(
    label: "Birthday",
  )
  getter slug = DynFork::Fields::SlugField.new(
    label: "Slug",
    slug_sources: ["hash", "username"]
  )
  getter password = DynFork::Fields::PasswordField.new(
    label: "Password",
  )
  # Do not save the value of this field to the database.
  # This field is for verification purposes only.
  getter confirm_password = DynFork::Fields::PasswordField.new(
    label: "Confirm password",
    ignored: true
  )
  getter active = DynFork::Fields::BoolField.new(
    label: "is active?",
    default: true
  )
end

Included Modules

Extended Modules

Defined in:

dynfork/model.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module DynFork::QPaladins::Fixtures

apply_fixture(fixture_name : String | Nil, collection_ptr : Pointer(Mongo::Collection)) : Nil apply_fixture

Instance methods inherited from module DynFork::QPaladins::Save

save : Bool save

Instance methods inherited from module DynFork::QPaladins::Password

update_password(old_password : String, new_password : String, field_name : String = "password") : Nil update_password, verify_password(password : String, field_name : String = "password") : Bool verify_password

Instance methods inherited from module DynFork::QPaladins::Check

check(collection_ptr : Pointer(Mongo::Collection), save? : Bool = false) : DynFork::Globals::OutputData check

Instance methods inherited from module DynFork::QPaladins::Groups

group_01(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), update? : Bool, save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType)), collection_ptr : Pointer(Mongo::Collection), id_ptr : Pointer(BSON::ObjectId | Nil)) : Nil group_01, group_02(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType)), collection_ptr : Pointer(Mongo::Collection)) : Nil group_02, group_03(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType)), collection_ptr : Pointer(Mongo::Collection)) : Nil group_03, group_04(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), update? : Bool, save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType))) : Nil group_04, group_05(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), update? : Bool, save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType))) : Nil group_05, group_06(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType)), collection_ptr : Pointer(Mongo::Collection), id_ptr : Pointer(BSON::ObjectId | Nil)) : Nil group_06, group_07(field_ptr : Pointer(DynFork::Globals::FieldTypes), error_symptom_ptr? : Pointer(Bool), save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType)), collection_ptr : Pointer(Mongo::Collection), id_ptr : Pointer(BSON::ObjectId | Nil)) : Nil group_07, group_08(field_ptr : Pointer(DynFork::Globals::FieldTypes), save? : Bool, result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType))) : Nil group_08, group_09(field_ptr : Pointer(DynFork::Globals::FieldTypes), result_map_ptr : Pointer(Hash(String, DynFork::Globals::ResultMapType))) : Nil group_09

Instance methods inherited from module DynFork::QPaladins::Tools

delete : Nil delete, print_err : Nil print_err, refrash_fields(doc_ptr : Pointer(BSON | Nil)) : Nil refrash_fields, valid? : Bool valid?

Instance methods inherited from module DynFork::Globals::Date

date_parse(date : String) : Time date_parse, datetime_parse(datetime : String) : Time datetime_parse

Instance methods inherited from struct DynFork::Extra

add_validation : Hash(String, String) add_validation, initialize initialize, post_create : Nil post_create, post_delete : Nil post_delete, post_update : Nil post_update, pre_create : Nil pre_create, pre_delete : Nil pre_delete, pre_update : Nil pre_update

Constructor methods inherited from struct DynFork::Extra

new new

Class methods inherited from struct DynFork::Extra

indexing : Nil indexing

Constructor Detail

def self.new(pull : JSON::PullParser) #

[View source]
def self.new #

[View source]

Class Method Detail

def self.full_model_name : String #

Get full Model name = ModuleName::StructureName.
Examples: Accounts::User | Accounts::UserProfile | Cars::ElectricCar | etc ...


[View source]
def self.meta : DynFork::Globals::CacheMetaDataType | Nil #

Metadata cache.


[View source]
def self.meta? : DynFork::Globals::CacheMetaDataType | Nil | Nil #

Metadata cache.


[View source]
def self.subclasses #

Get a list of Models.


[View source]

Instance Method Detail

Field for the date and time the document was created.
Example: 1970-01-01T00:00:00


[View source]

Field for the document identifier.
Example: 507c7f79bcf86cd7994f6c0e


[View source]
def object_id : BSON::ObjectId | Nil #

Get ObjectId from hash field.


[View source]

Field for the date and time the document was updated.
Example: 1970-01-01T00:00:00


[View source]