Sha256: 711723a543fa35a5a711a53f735caa4851ee1a1c9d773c9223bb29caa607481a

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'erb'
require 'yaml'
require_relative '../support/configuration'

module Dsu
  module Services
    class ConfigurationLoaderService
      include Dsu::Support::Configuration

      def initialize(default_options: nil)
        unless default_options.nil? ||
               default_options.is_a?(Hash) ||
               default_options.is_a?(ActiveSupport::HashWithIndifferentAccess)
          raise ArgumentError, 'default_options must be a Hash or ActiveSupport::HashWithIndifferentAccess'
        end

        @default_options = default_options || {}
        @default_options = @default_options.with_indifferent_access if @default_options.is_a?(Hash)
      end

      def call
        config_options.merge(default_options).with_indifferent_access
      end

      private

      attr_reader :default_options

      def config_options
        return Support::Configuration::DEFAULT_DSU_OPTIONS unless config_file?

        @config_options ||= YAML.safe_load(ERB.new(File.read(config_file)).result)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dsu-0.1.0.alpha.5 lib/dsu/services/configuration_loader_service.rb