<commit_before>module VagrantPlugins
  module Dotvm
    class Dotvm
      def initialize(path = nil)
        fail 'path must be set.' until path
        @path = path
      end

      def inject(vc)
        begin
          init_instance
          load_options
          load_projects
          Injector::Instance.inject @instance, vc
        rescue VagrantPlugins::Dotvm::Config::InvalidConfigError => e
          raise Vagrant::Errors::VagrantError.new, "DotVM: #{e.file}: #{e.message}"
        rescue Psych::SyntaxError => e
          raise Vagrant::Errors::VagrantError.new, "DotVM: #{e.file}: Syntax error, line #{e.line}, #{e.problem}"
        end
      end

      private

      def parse_variables(path)
        result = {}

        Dir[path].each do |fname|
          yaml = YAML.load_file(fname) || {}
          yaml.each do |name, value|
            fail "Variable #{name} already exists." if result.key? name
            result[name] = value
          end
        end

        result
      end

      def init_instance
        @instance = Config::Instance.new
        @instance.variables.append_group 'env', ENV
        @instance.variables.append_group 'global', (parse_variables "#{@path}/variables/*.{yaml,yml}")
      end

      def load_options
        Dir["#{@path}/options/*.{yaml,yml}"].each do |file|
          @instance.options = Replacer.new
            .on(YAML.load_file(file) || {})
            .using(@instance.variables)
            .result
        end
      end

      def load_projects
        Dir["#{@path}/projects/*"].each do |dir|
          project = @instance.new_project
          project.variables.append_group 'project', (parse_variables "#{dir}/variables/*.{yaml,yml}")
          project.variables.append_group(
            'host',
            {
              'project_dir' => dir,
              'files_dir' => "#{dir}/files"<commit_msg>only one file in options was taken into account (fixes #48)<commit_after>module VagrantPlugins
  module Dotvm
    class Dotvm
      def initialize(path = nil)
        fail 'path must be set.' until path
        @path = path
      end

      def inject(vc)
        begin
          init_instance
          load_options
          load_projects
          Injector::Instance.inject @instance, vc
        rescue VagrantPlugins::Dotvm::Config::InvalidConfigError => e
          raise Vagrant::Errors::VagrantError.new, "DotVM: #{e.file}: #{e.message}"
        rescue Psych::SyntaxError => e
          raise Vagrant::Errors::VagrantError.new, "DotVM: #{e.file}: Syntax error, line #{e.line}, #{e.problem}"
        end
      end

      private

      def parse_variables(path)
        result = {}

        Dir[path].each do |fname|
          yaml = YAML.load_file(fname) || {}
          yaml.each do |name, value|
            fail "Variable #{name} already exists." if result.key? name
            result[name] = value
          end
        end

        result
      end

      def init_instance
        @instance = Config::Instance.new
        @instance.variables.append_group 'env', ENV
        @instance.variables.append_group 'global', (parse_variables "#{@path}/variables/*.{yaml,yml}")
      end

      def load_options
        options = {}

        Dir["#{@path}/options/*.{yaml,yml}"].each do |file|
          options.merge!(YAML.load_file(file) || {})
        end

        @instance.options = Replacer.new
            .on(options)
            .using(@instance.variables)
            .result
      end

      def load_projects
        Dir["#{@path}/projects/*"].each do |dir|
          project = @instance.new_project
          project.variables.append_group 'project', (parse_variables "#{dir}/variables/*.{yaml,yml}")
          project.variables.append_group(
            'host',
            {
              'project_dir' => dir,
              'files_dir' => "#{dir}/files"
{'fraction_non_alphanumeric': 0.1237327787886665, 'fraction_numerical': 0.0005198856251624642, 'mean_word_length': 1.9464012251148546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6058526', 'n_tokens_mistral': 1127, 'n_tokens_neox': 1100, 'n_words': 247}