lib/declare_schema/model.rb
# Add field validations according to arguments in the
# field declaration
Add field validations according to arguments in the
field declaration
Add field validations according to arguments in the field declaration
def _add_validations_for_field(name, type, args, options)
        validates_presence_of   name if :required.in?(args)
        validates_uniqueness_of name, allow_nil: !:required.in?(args) if :unique.in?(args)
        if (validates_options = options[:validates])
          validates name, validates_options
        end
        if (type_class = DeclareSchema.to_class(type))
          if type_class.public_method_defined?("validate")
            validate do |record|
              v = record.send(name)&.validate
              record.errors.add(name, v) if v.is_a?(String)
            end
          end
        end
      end
def _add_validations_for_field ( name , type , args , options ) validates_presence_of name if :required . in? ( args ) validates_uniqueness_of name , allow_nil : ! :required . in? ( args ) if :unique . in? ( args ) if ( validates_options = options [ :validates ] ) validates name , validates_options end if ( type_class = DeclareSchema . to_class ( type ) ) if type_class . public_method_defined? ( "validate" ) validate do | record | v = record . send ( name ) &. validate record . errors . add ( name , v ) if v . is_a? ( String ) end end end end
Add field validations according to arguments in the
field declaration
Add field validations according to arguments in the field declaration
# Support for custom validations
name
<not_specific>
type
<not_specific>
args
<not_specific>
options
<not_specific>