Sha256: d4c73622ff2cdd31858650058fab6e0902c36fc6eb5ca46d9b6dd04aff325066

Contents?: true

Size: 672 Bytes

Versions: 4

Compression:

Stored size: 672 Bytes

Contents

# frozen_string_literal: true

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

      alias to_h to_hash

      private

      # Getters/Setters
      attr_accessor :storage
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
light-services-0.5.3 lib/light/services/messages.rb
light-services-0.5.2 lib/light/services/messages.rb
light-services-0.5.1 lib/light/services/messages.rb
light-services-0.5.0 lib/light/services/messages.rb