Sha256: f18bfde8893abee778fb4d7202d0fb46d7ab083790c15c36d83be0b712e18285

Contents?: true

Size: 629 Bytes

Versions: 3

Compression:

Stored size: 629 Bytes

Contents

require "hanami-validations"

module Prezzo
  module Context
    def self.included(base)
      base.class_eval do
        base.include(Hanami::Validations)
      end
    end

    def valid?
      validation.success?
    end

    def errors
      validation.errors
    end

    def fetch(key, default = nil)
      if default.nil?
        value = attributes.fetch(key)
      else
        value = attributes.fetch(key, default)
        value = default if value.nil?
      end

      value
    end

    def attributes
      validation.output
    end

    private

    def validation
      @_validation ||= validate
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prezzo-0.3.0 lib/prezzo/context.rb
prezzo-0.2.2 lib/prezzo/context.rb
prezzo-0.2.1 lib/prezzo/context.rb