Sha256: 7e0a6efea8f40a2fc2d95aae9cd9275cab1992e03d19ece49d41d3e465dbbee4

Contents?: true

Size: 1.2 KB

Versions: 7

Compression:

Stored size: 1.2 KB

Contents

require 'yaml'

module Overcommit
  # Manages configuration file loading.
  class ConfigurationLoader
    DEFAULT_CONFIG_PATH = File.join(OVERCOMMIT_HOME, 'config', 'default.yml')

    class << self
      def load_repo_config
        overcommit_yml = File.join(Overcommit::Utils.repo_root,
                                   OVERCOMMIT_CONFIG_FILE_NAME)

        if File.exist?(overcommit_yml)
          load_file(overcommit_yml)
        else
          default_configuration
        end
      end

      def default_configuration
        @default_config ||= load_from_file(DEFAULT_CONFIG_PATH)
      end

      private

      # Loads a configuration, ensuring it extends the default configuration.
      def load_file(file)
        config = load_from_file(file)

        default_configuration.merge(config)
      rescue => error
        raise Overcommit::Exceptions::ConfigurationError,
              "Unable to load configuration from '#{file}': #{error}",
              error.backtrace
      end

      def load_from_file(file)
        hash =
          if yaml = YAML.load_file(file)
            yaml.to_hash
          else
            {}
          end

        Overcommit::Configuration.new(hash)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
overcommit-0.23.0 lib/overcommit/configuration_loader.rb
overcommit-0.22.0 lib/overcommit/configuration_loader.rb
jawshooah-overcommit-0.22.0 lib/overcommit/configuration_loader.rb
overcommit-0.21.0 lib/overcommit/configuration_loader.rb
overcommit-0.20.0 lib/overcommit/configuration_loader.rb
overcommit-0.19.0 lib/overcommit/configuration_loader.rb
overcommit-0.18.0 lib/overcommit/configuration_loader.rb