Sha256: 678318ae531ab3162fa0e68fe4089fc9919860dd37ca2e028078a08f64086456

Contents?: true

Size: 636 Bytes

Versions: 4

Compression:

Stored size: 636 Bytes

Contents

module ActiveModel
  class Error

    attr_reader :messages

    def initialize(initial_msgs = {})
      @messages = Hash.new { |h, k| h[k] = [] }
      initial_msgs.each { |attr, msgs| @messages[attr] = msgs.uniq }
    end

    def [](attribute)
      messages[attribute]
    end

    def delete(attribute)
      messages.delete(attribute)
    end

    def empty?
      messages.empty?
    end

    def clear
      @messages.clear
    end

    alias non_reactive_clear clear

    def add(attribute, message = :invalid, _options = {})
      @messages[attribute] << message unless @messages[attribute].include? message
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyper-model-1.0.alpha1.8 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1.7 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1.6 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1.5 lib/reactive_record/active_record/error.rb