Sha256: 0e2a46da8a917bee2ae8e3d239c1de9f87cb118086f4623f59de20e1ca0ca4bc

Contents?: true

Size: 620 Bytes

Versions: 4

Compression:

Stored size: 620 Bytes

Contents

module Light
  module Services
    class Messages
      def initialize
        @storage = {}
      end

      def add(key, message)
        @storage[key] ||= []
        @storage[key] << message
      end

      def from_record(record)
        record.errors.to_h.each do |key, value|
          add(key, value)
        end
      end

      def delete(key)
        @storage.delete(key)
      end

      def blank?
        @storage.empty?
      end

      def any?
        !blank?
      end

      def to_hash
        @storage
      end

      private

      # Getters/Setters
      attr_accessor :storage
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
light-services-0.4.0 lib/light/services/messages.rb
light-services-0.3.0 lib/light/services/messages.rb
light-services-0.2.0 lib/light/services/messages.rb
light-services-0.1.0 lib/light/services/messages.rb