Module: Hanami::Validations::ClassMethods
- Defined in:
- gems/gems/hanami-validations-1.3.5/lib/hanami/validations.rb
Overview
Validations DSL
Instance Method Summary collapse
-
#messages(type) ⇒ Object
Define the type of engine for error messages.
-
#messages_path(path) ⇒ Object
Define the path where to find translation file.
-
#namespace(name = nil) ⇒ Object
Namespace for error messages.
-
#predicate(name, message: 'is invalid', &blk) ⇒ Object
Define an inline predicate.
-
#predicates(mod) ⇒ Object
Assign a set of shared predicates wrapped in a module.
-
#validations(&blk) ⇒ Object
Define validation rules from the given block.
Instance Method Details
#messages(type) ⇒ Object
Define the type of engine for error messages.
Accepted values are :yaml
(default), :i18n
.
Source: | on GitHub
def (type) self. = type end |
#messages_path(path) ⇒ Object
Define the path where to find translation file
Source: | on GitHub
def (path) self. = path end |
#namespace(name = nil) ⇒ Object
Namespace for error messages.
Source: | on GitHub
def namespace(name = nil) if name.nil? Namespace.new(_namespace, self) else self._namespace = name.to_s end end |
#predicate(name, message: 'is invalid', &blk) ⇒ Object
Define an inline predicate
Source: | on GitHub
def predicate(name, message: 'is invalid', &blk) _predicates << InlinePredicate.new(name, , &blk) end |
#predicates(mod) ⇒ Object
Assign a set of shared predicates wrapped in a module
Source: | on GitHub
def predicates(mod) self._predicates_module = mod end |
#validations(&blk) ⇒ Object
Define validation rules from the given block.
Source: | on GitHub
def validations(&blk) # rubocop:disable Metrics/AbcSize schema_predicates = _predicates_module || __predicates base = _build(predicates: schema_predicates, &_base_rules) schema = _build(predicates: schema_predicates, rules: base.rules, &blk) schema.configure(&_schema_config) schema.configure(&_schema_predicates) schema.extend() unless _predicates.empty? self.schema = schema.new end |