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`.
201 202 203 |
# File 'lib/hanami/validations.rb', line 201 def (type) self. = type end |
#messages_path(path) ⇒ Object
Define the path where to find translation file
219 220 221 |
# File 'lib/hanami/validations.rb', line 219 def (path) self. = path end |
#namespace(name = nil) ⇒ Object
Namespace for error messages.
246 247 248 249 250 251 252 |
# File 'lib/hanami/validations.rb', line 246 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
150 151 152 |
# File 'lib/hanami/validations.rb', line 150 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
181 182 183 |
# File 'lib/hanami/validations.rb', line 181 def predicates(mod) self._predicates_module = mod end |
#validations(&blk) ⇒ Object
Define validation rules from the given block.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/hanami/validations.rb', line 93 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 |