Module: Hanami::Validations

Defined in:
gems/gems/hanami-validations-1.3.4/lib/hanami/validations.rb,
gems/gems/hanami-validations-1.3.4/lib/hanami/validations/form.rb,
gems/gems/hanami-validations-1.3.4/lib/hanami/validations/version.rb,
gems/gems/hanami-validations-1.3.4/lib/hanami/validations/namespace.rb,
gems/gems/hanami-validations-1.3.4/lib/hanami/validations/predicates.rb,
gems/gems/hanami-validations-1.3.4/lib/hanami/validations/inline_predicate.rb

Overview

Hanami::Validations is a set of lightweight validations for Ruby objects.

Examples:

require 'hanami/validations'

class Signup
  include Hanami::Validations

  validations do
    # ...
  end
end

Since:

  • 0.1.0

Defined Under Namespace

Modules: ClassMethods, Form, Predicates

Constant Summary

VERSION =

Since:

  • 0.1.0

'1.3.4'.freeze

Instance Method Summary collapse

Instance Method Details

#initialize(input = {}) ⇒ Object

Initialize a new instance of a validator

Parameters:

  • input (#to_h) (defaults to: {})

    a set of input data

Since:

  • 0.6.0

def initialize(input = {})
  @input = input.to_h
end

#to_hHash

Returns a Hash with the defined attributes as symbolized keys, and their relative values.

Returns:

  • (Hash)

Since:

  • 0.1.0

def to_h
  validate.output
end

#validateDry::Validations::Result

Validates the object.

Returns:

  • (Dry::Validations::Result)

Since:

  • 0.2.4

def validate
  self.class.schema.call(@input)
end