Sha256: d6704524f1f53b44aea01d52d1080850ede9caf79d1a2f3427f16691c3d479c6

Contents?: true

Size: 600 Bytes

Versions: 12

Compression:

Stored size: 600 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

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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
hyper-model-1.0.alpha1.4 lib/reactive_record/active_record/error.rb
hyper-model-0.99.6 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1.3 lib/reactive_record/active_record/error.rb
hyper-model-0.99.5 lib/reactive_record/active_record/error.rb
hyper-model-0.99.4 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1.2 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1.1 lib/reactive_record/active_record/error.rb
hyper-model-1.0.alpha1 lib/reactive_record/active_record/error.rb
hyper-model-0.99.3 lib/reactive_record/active_record/error.rb
hyper-model-0.99.2 lib/reactive_record/active_record/error.rb
hyper-model-0.99.1 lib/reactive_record/active_record/error.rb
hyper-model-0.99.0 lib/reactive_record/active_record/error.rb