<commit_before>module Analytical
  module Modules
    class DummyModule
      include Analytical::Modules::Base
      def method_missing(method, *args, &block); nil; end
    end
  end

  class Api
    attr_accessor :options, :modules

    def initialize(options={})
      @options = options
      @modules = @options[:modules].inject(ActiveSupport::OrderedHash.new) do |h, m|
        module_options = @options.merge(@options[m] || {})
        module_options.delete(:modules)
        module_options[:session_store] = Analytical::SessionCommandStore.new(@options[:session], m) if @options[:session]
        h[m] = "Analytical::Modules::#{m.to_s.camelize}".constantize.new(module_options)
        h
      end
      @dummy_module = Analytical::Modules::DummyModule.new
    end

    #
    # Catch commands such as :track, :identify and send them on to all of the modules.
    # Or... if a module name is passed, return that module so it can be used directly, ie:
    # analytical.console.go 'make', :some=>:cookies
    #
    def method_missing(method, *args, &block)
      method = method.to_sym
      if @modules.keys.include?(method)
        @modules[method]
      elsif available_modules.include?(method)
        @dummy_module
      else
        process_command method, *args
      end
    end
<commit_msg>raise an explanatory error when the config is bad<commit_after>module Analytical
  module Modules
    class DummyModule
      include Analytical::Modules::Base
      def method_missing(method, *args, &block); nil; end
    end
  end

  class Api
    attr_accessor :options, :modules

    def initialize(options={})
      @options = options
      @modules = @options[:modules].inject(ActiveSupport::OrderedHash.new) do |h, m|
        module_options = @options.merge(@options[m] || {})
        module_options.delete(:modules)
        module_options[:session_store] = Analytical::SessionCommandStore.new(@options[:session], m) if @options[:session]
        h[m] = get_mod(m).new(module_options)
        h
      end
      @dummy_module = Analytical::Modules::DummyModule.new
    end

    def get_mod(name)
      name = name.to_s.camelize
      "Analytical::Modules::#{name}".constantize
    rescue NameError
      raise "You're trying to configure a module named '#{name}', but " +
        "Analytical doesn't have one. Check your analytical.yml file for typos."
    end

    #
    # Catch commands such as :track, :identify and send them on to all of the modules.
    # Or... if a module name is passed, return that module so it can be used directly, ie:
    # analytical.console.go 'make', :some=>:cookies
    #
    def method_missing(method, *args, &block)
      method = method.to_sym
      if @modules.keys.include?(method)
        @modules[method]
      elsif available_modules.include?(method)
        @dummy_module
      else
        process_command method, *args
      end
    end

{'fraction_non_alphanumeric': 0.10903426791277258, 'fraction_numerical': 0.0, 'mean_word_length': 3.013888888888889, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4586814', 'n_tokens_mistral': 864, 'n_tokens_neox': 856, 'n_words': 232}