Sha256: 219e9ed62f9914334ae5acc0bdf57ad4953ece2648cda5e00ad7cffc18a7b001

Contents?: true

Size: 927 Bytes

Versions: 12

Compression:

Stored size: 927 Bytes

Contents

# frozen_string_literal: true

require_relative '../models/entry'

module Dsu
  module Services
    class EntryHydratorService
      def initialize(entry_hash:, options: {})
        raise ArgumentError, 'entry_hash is nil' if entry_hash.nil?
        raise ArgumentError, 'entry_hash is the wrong object type' unless entry_hash.is_a?(Hash)
        raise ArgumentError, 'options is nil' if options.nil?
        raise ArgumentError, 'options is the wrong object type' unless options.is_a?(Hash)

        @entry_hash = entry_hash
        @options = options || {}
      end

      def call
        Dsu::Models::Entry.new(**entry_hash)
      end

      class << self
        def hydrate(entries_array:, options: {})
          entries_array.map do |entry_hash|
            new(entry_hash: entry_hash, options: options).call
          end
        end
      end

      private

      attr_reader :entry_hash, :options
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dsu-1.2.1 lib/dsu/services/entry_hydrator_service.rb
dsu-1.2.0 lib/dsu/services/entry_hydrator_service.rb
dsu-1.1.2 lib/dsu/services/entry_hydrator_service.rb
dsu-1.1.1 lib/dsu/services/entry_hydrator_service.rb
dsu-1.1.0.alpha.2 lib/dsu/services/entry_hydrator_service.rb
dsu-1.1.0.alpha.1 lib/dsu/services/entry_hydrator_service.rb
dsu-1.0.0 lib/dsu/services/entry_hydrator_service.rb
dsu-0.1.0.alpha.5 lib/dsu/services/entry_hydrator_service.rb
dsu-0.1.0.alpha.4 lib/dsu/services/entry_hydrator_service.rb
dsu-0.1.0.alpha.3 lib/dsu/services/entry_hydrator_service.rb
dsu-0.1.0.alpha.2 lib/dsu/services/entry_hydrator_service.rb
dsu-0.1.0.alpha.1 lib/dsu/services/entry_hydrator_service.rb