Module: Hanami::Validations::ClassMethods
- Defined in:
- 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`.
208 209 210 |
# File 'lib/hanami/validations.rb', line 208 def (type) self. = type end |
#messages_path(path) ⇒ Object
Define the path where to find translation file
226 227 228 |
# File 'lib/hanami/validations.rb', line 226 def (path) self. = path end |
#namespace(name = nil) ⇒ Object
Namespace for error messages.
253 254 255 256 257 258 259 |
# File 'lib/hanami/validations.rb', line 253 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
157 158 159 |
# File 'lib/hanami/validations.rb', line 157 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
188 189 190 |
# File 'lib/hanami/validations.rb', line 188 def predicates(mod) self._predicates_module = mod end |
#validations(&blk) ⇒ Object
Define validation rules from the given block.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hanami/validations.rb', line 100 def validations(&blk) schema_predicates = __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 |