Sha256: 0368a5d64df5880780074baf343dad21ffc15dbddb2b164ab3a98d9e370cf817

Contents?: true

Size: 883 Bytes

Versions: 1

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true

require "yaml"
require "active_support/core_ext/hash/indifferent_access"

# Provides a collection of the configured tools
module Reviewer
  class Loader
    class MissingConfigurationError < StandardError; end
    class InvalidConfigurationError < StandardError; end

    attr_reader :configuration

    def initialize
      @configuration = HashWithIndifferentAccess.new(configuration_hash)
    end

    def to_h
      configuration
    end

    private

    def configuration_hash
      @configuration_hash ||= YAML.load_file(Reviewer.configuration.file)
    rescue Errno::ENOENT
      raise MissingConfigurationError, "Tools configuration file couldn't be found - #{Reviewer.configuration.file}"
    rescue Psych::SyntaxError => e
      raise InvalidConfigurationError, "Tools configuration file has a syntax error - #{e.message}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reviewer-0.1.1 lib/reviewer/loader.rb