<commit_before>module MotionBuild

  # Config class provides a layered approach to access project-specific options.
  # The exact values that you get from config are based on what you have in
  # project file, what is resolved for current build action, and what is the
  # current task.
  class Config
    attr_accessor :validate
    def initialize
      @local_options = {}
      @validate = true

      @options = {}
      @validators = {}

      load_options(File.join(File.dirname(__FILE__), 'config_options.dsl.rb'))
    end

    def override(opt_name, value)
      @local_options[opt_name] = value
    end

    def get(opt_name)
      opt = @options[opt_name]
      raise RuntimeError, "Unknown option '#{opt_name}'" unless opt
      
      local_opt = @local_options[opt_name]
      raise RuntimeError, "Cannot override option '#{opt_name}'" if local_opt && opt[:no_override]
      return local_opt if local_opt && validate!(opt, local_opt)

      val = opt.value(self)
      return val if validate!(opt, val)
    end

    def validate!(opt, value)
      return true unless @validate
      return true unless opt[:validate]
      validator_block = @validators[opt[:validate]]
      validator_block.call(opt.name, value, self)
      true
    end

    def load_options(*args, &block)
      raise RuntimeError, "You must specify either a filename or a block" if (args.count >= 1 && block_given?) || (args.count == 0 && ! block_given?)
      dsl = DSLLoader.new
      if block_given?
        dsl.instance_eval(&block)
      else
        dsl.instance_eval(open(args.first).read, args.first, 1)
      end
      @options.merge!(dsl.options)
      @validators.merge!(dsl.validators)
    end

    private
    class ValidationError < RuntimeError; end

    class DSLLoader
      attr_reader :options, :validators
      def initialize
        @options = {}
        @validators = {}
      end

      def option(name, *params, &block)
        params = params.first || {}<commit_msg>DSL no longer calls the block from inside it's instance<commit_after>module MotionBuild

  # Config class provides a layered approach to access project-specific options.
  # The exact values that you get from config are based on what you have in
  # project file, what is resolved for current build action, and what is the
  # current task.
  class Config
    attr_accessor :validate
    def initialize
      @local_options = {}
      @validate = true

      @options = {}
      @validators = {}

      load_options(File.join(File.dirname(__FILE__), 'config_options.dsl.rb'))
    end

    def override(opt_name, value)
      @local_options[opt_name] = value
    end

    def get(opt_name)
      opt = @options[opt_name]
      raise RuntimeError, "Unknown option '#{opt_name}'" unless opt
      
      local_opt = @local_options[opt_name]
      raise RuntimeError, "Cannot override option '#{opt_name}'" if local_opt && opt[:no_override]
      return local_opt if local_opt && validate!(opt, local_opt)

      val = opt.value(self)
      return val if validate!(opt, val)
    end

    def validate!(opt, value)
      return true unless @validate
      return true unless opt[:validate]
      validator_block = @validators[opt[:validate]]
      validator_block.call(opt.name, value, self)
      true
    end

    def load_options(*args, &block)
      raise RuntimeError, "You must specify either a filename or a block" if (args.count >= 1 && block_given?) || (args.count == 0 && ! block_given?)
      dsl = DSLLoader.new
      if block_given?
        block.call(dsl)
      else
        dsl.instance_eval(open(args.first).read, args.first, 1)
      end
      @options.merge!(dsl.options)
      @validators.merge!(dsl.validators)
    end

    private
    class ValidationError < RuntimeError; end

    class DSLLoader
      attr_reader :options, :validators
      def initialize
        @options = {}
        @validators = {}
      end

      def option(name, *params, &block)
        params = params.first || {}
{'fraction_non_alphanumeric': 0.09738955823293173, 'fraction_numerical': 0.0015060240963855422, 'mean_word_length': 2.7665406427221173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5154287', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1153, 'n_words': 353}