Sha256: 6874064c9a90964a1fb51a35f58f39c69c364a9fbfee88aac0c6929a3d40320e

Contents?: true

Size: 1.32 KB

Versions: 18

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

module Diffend
  module Config
    # Class used to figure out the file from which we should load the settings
    module FileFinder
      # Names of the files or paths where we will look for the settings
      #
      # @note We do the double dot trick, to look outside of the current dir because when
      #   executed from a docker container, we copy the local uncommitted settings into the
      #   dir above the app location not to pollute the reset state of the git repo
      #
      # @note Order is important, as for local env we should load from
      #   local file (if present first)
      FILE_NAMES = %w[
        .diffend.yml
      ].map { |name| ["../#{name}", name] }.tap(&:flatten!).freeze

      private_constant :FILE_NAMES

      class << self
        # Looks for Diffend settings file for a given env
        #
        # @param build_path [String] path of the current build
        #
        # @return [String] path to the file from which we should load all the settings
        def call(build_path)
          FILE_NAMES
            .map { |name| File.join(build_path, name) }
            .map { |name| Dir[name] }
            .find { |selection| !selection.empty? }
            .tap { |path| path || raise(Errors::MissingConfigurationFile) }
            .first
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
diffend-monitor-0.2.31 lib/diffend/config/file_finder.rb
diffend-0.2.31 lib/diffend/config/file_finder.rb
diffend-monitor-0.2.30 lib/diffend/config/file_finder.rb
diffend-0.2.30 lib/diffend/config/file_finder.rb
diffend-0.2.29 lib/diffend/config/file_finder.rb
diffend-monitor-0.2.28 lib/diffend/config/file_finder.rb
diffend-0.2.28 lib/diffend/config/file_finder.rb
diffend-monitor-0.2.27 lib/diffend/config/file_finder.rb
diffend-0.2.27 lib/diffend/config/file_finder.rb
diffend-0.2.26 lib/diffend/config/file_finder.rb
diffend-0.2.25 lib/diffend/config/file_finder.rb
diffend-0.2.24 lib/diffend/config/file_finder.rb
diffend-0.2.23 lib/diffend/config/file_finder.rb
diffend-0.2.19 lib/diffend/config/file_finder.rb
diffend-0.2.18 lib/diffend/config/file_finder.rb
diffend-0.2.17 lib/diffend/config/file_finder.rb
diffend-0.2.16 lib/diffend/config/file_finder.rb
diffend-0.2.15 lib/diffend/config/file_finder.rb