Module: Hanami::Validations
- Defined in:
- lib/hanami/validations.rb,
lib/hanami/validations/form.rb,
lib/hanami/validations/version.rb,
lib/hanami/validations/namespace.rb,
lib/hanami/validations/predicates.rb,
lib/hanami/validations/inline_predicate.rb
Overview
Hanami::Validations is a set of lightweight validations for Ruby objects.
Defined Under Namespace
Modules: ClassMethods, Form, Predicates Classes: InlinePredicate, Namespace
Constant Summary collapse
- DEFAULT_MESSAGES_ENGINE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:yaml
- VERSION =
'0.7.0'.freeze
Class Method Summary collapse
-
.included(base) ⇒ Object
private
Override Ruby’s hook for modules.
Instance Method Summary collapse
-
#initialize(input = {}) ⇒ Object
Initialize a new instance of a validator.
-
#to_h ⇒ Hash
Returns a Hash with the defined attributes as symbolized keys, and their relative values.
-
#validate ⇒ Dry::Validations::Result
Validates the object.
Class Method Details
.included(base) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Override Ruby’s hook for modules.
rubocop:disable Metrics/MethodLength
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/hanami/validations.rb', line 43 def self.included(base) base.class_eval do extend ClassMethods include Utils::ClassAttribute class_attribute :schema class_attribute :_messages class_attribute :_messages_path class_attribute :_namespace class_attribute :_predicates_module class_attribute :_predicates self._predicates = Set.new end end |
Instance Method Details
#initialize(input = {}) ⇒ Object
Initialize a new instance of a validator
333 334 335 |
# File 'lib/hanami/validations.rb', line 333 def initialize(input = {}) @input = input.to_h end |
#to_h ⇒ Hash
Returns a Hash with the defined attributes as symbolized keys, and their relative values.
352 353 354 |
# File 'lib/hanami/validations.rb', line 352 def to_h validate.output end |
#validate ⇒ Dry::Validations::Result
Validates the object.
342 343 344 |
# File 'lib/hanami/validations.rb', line 342 def validate self.class.schema.call(@input) end |