module Crecto::Changeset(T)

Overview

Changeset allows validating data, and tracking changes.

Defined in:

crecto/changeset/changeset.cr
crecto/changeset.cr

Instance Method Summary

Instance Method Detail

def changeset(instance) #

[View source]
def unique_constraint #

TODO not done - https://hexdocs.pm/ecto/Ecto.Changeset.html#unique_constraint/3


[View source]
def validate_acceptance #

TODO not done


[View source]
def validate_confirmation #

TODO not done


[View source]
def validate_exclusion(fields : Array(Symbol), in : Array | Range) #

Validate the inclusion of fields values is not in


[View source]
def validate_exclusion(field : Symbol, in : RangeTypes) #

Validate the inclusion of field value is not in in


[View source]
def validate_exclusion(field : Symbol, in : Array) #

Validate the inclusion of field value is not in in


[View source]
def validate_format(fields : Array(Symbol), pattern : Regex) #

Validate the format for an array of fields values using a pattern


[View source]
def validate_format(field : Symbol, pattern : Regex) #

Validate the format for the value of field using a pattern


[View source]
def validate_inclusion(fields : Array(Symbol), in : Array | Range) #

Validate the inclusion of fields values is in in


[View source]
def validate_inclusion(field : Symbol, in : RangeTypes) #

Validate the inclusion of field value is in in


[View source]
def validate_inclusion(field : Symbol, in : Array) #

Validate the inclusion of field value is in in


[View source]
def validate_length(field : Symbol, **opts) #

Validate the length of field value using the following opts:

  • is: Int32
  • min: Int32
  • max: Int32

[View source]
def validate_length(fields : Array(Symbol), **opts) #

Validate the length of fields value using the following opts:

  • is: Int32
  • min: Int32
  • max: Int32

[View source]
def validate_number #

TODO not done


[View source]
def validate_required(fields : Array(Symbol)) #

Validates that an array of fields is present.


[View source]
def validate_required(field : Symbol) #

Validate that a field is present.


[View source]
def validates(field, **constrains) #

Assigns multiple validations for one or many fields. contrains can include:

  • presence: Bool
  • format: {pattern: Regex}
  • inclusion: {in: (Array | Range)}
  • exclusion: {in: (Array | Range)}
  • length: {is: Int32?, min: Int32?, max: Int32?}
class User
  include Crecto::Schema
  extend Crecto::Changeset(User)

  schema "users" do
    field :first_name, String
    field :last_name, String
    field :rank, Int32
  end

  validates :first_name,
    length: {min: 3, max: 9}

  validates [:first_name, :last_name],
    presence: true,
    format: {pattern: /^[a-zA-Z]+$/},
    exclusion: {in: ["foo", "bar"]}

  validates :rank,
    inclusion: {in: 1..100}
end

[View source]