Sha256: 532438b175508ba64d258dc7573389001f394b124df23b05ae4a201ecb510669

Contents?: true

Size: 995 Bytes

Versions: 6

Compression:

Stored size: 995 Bytes

Contents

require 'yaml'

module Moj
  module Tribunals
    class ConfigLoader 
      attr_accessor :config_path

      def initialize(config_path=default_config_path)
        self.config_path = config_path
      end

      def load
        data = {}
        config_files.each do |file|
          name = File.basename(file).split('.').first.to_sym

          loaded_config = load_file(file)
          data[name] = loaded_config['tribunal']
        end
        data
      end

      def config_file_for(tribunal_name)
        config_files.find{|f| File.basename(f) == tribunal_name.to_s + '.yml'}
      end

      def config_files
        Dir.glob(File.join(config_path, '*.yml'))
      end

      def load_file(file)
        YAML.load_file(file)
      end

      private

        def default_config_path
          File.expand_path(
            File.join( 
              File.dirname(__FILE__), 
              '..', '..', '..', 'config', 'tribunals' 
            )
          )
        end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
moj_tribunals_config-1.6.0 lib/moj/tribunals/config_loader.rb
moj_tribunals_config-1.5.2 lib/moj/tribunals/config_loader.rb
moj_tribunals_config-1.5.1 lib/moj/tribunals/config_loader.rb
moj_tribunals_config-1.5.0 lib/moj/tribunals/config_loader.rb
moj_tribunals_config-1.4.0 lib/moj/tribunals/config_loader.rb
moj_tribunals_config-1.3.0 lib/moj/tribunals/config_loader.rb