Sha256: 08eb52176a6c74cf27d75ba1ce13b316fb2d33998b18ceef216d0050bf4d4df8

Contents?: true

Size: 573 Bytes

Versions: 5

Compression:

Stored size: 573 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?
        attributes.fetch(key)
      else
        attributes.fetch(key, default) || default
      end
    end

    def attributes
      validation.output
    end

    private

    def validation
      @_validation ||= validate
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
prezzo-0.5.1 lib/prezzo/context.rb
prezzo-0.5.0 lib/prezzo/context.rb
prezzo-0.4.1 lib/prezzo/context.rb
prezzo-0.4.0 lib/prezzo/context.rb
prezzo-0.3.1 lib/prezzo/context.rb