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