Sha256: 964b1b372b2323154c12645cc16c0e3b782aac8b541b0ded193123c49f5263a5

Contents?: true

Size: 648 Bytes

Versions: 1

Compression:

Stored size: 648 Bytes

Contents

require 'hanami/validations'

module Forminator

  class InvalidStep < StandardError; end

  class Step

    include ::Hanami::Validations

    attr_reader :params, :object

    def self.call(object, params, **options)
      step = new(params)
      validity = step.valid?
      if validity && step.persist?
        step.persist(object: object, persist: options[:persist])
      end

      [{ valid: validity }, params]
    end

    def valid?
      validate.success?
    end

    def persist?
      false
    end

    def persist(object:, persist: nil)
      persist&.call(object) ||
      Forminator.config.persist.call(object)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
forminator-0.1.0 lib/forminator/step.rb