<commit_before>require "json"

# Public: Contains the configuration values set in the configuration.json file.
# Provides a Singleton that can be accessed throughout the application.
class Configuration

  attr_reader :colors_enabled
  attr_reader :region
  attr_reader :policy_suffix
  attr_reader :policy_version
  attr_reader :static_policy_directory
  attr_reader :template_policy_directory
  attr_reader :roles_directory

  # Internal: Constructor. Sets the `instance` variable, which is the access point
  # for the Singleton.
  #
  # project_root  - The String path to the directory the project is running in
  # file_path     - The String path from `project_root` to the configuration
  #                 file
  def initialize(project_root, file_path)
    @project_root = project_root;
    json = JSON.parse(File.read(absolute_path(file_path)))
    @colors_enabled = json["colors-enabled"]
    @policy_suffix = json["policies"]["suffix"]
    @policy_version = json["policies"]["version"]
    @static_policy_directory = absolute_path(json["policies"]["static"]["directory"])
    @template_policy_directory = absolute_path(json["policies"]["templates"]["directory"])
    @roles_directory = absolute_path(json["roles"]["directory"])
    @region = json["region"]
  end

  # Public: Take a path relative to the project root and turn it into an
  # absolute path
  #
  # absolute_path - The String path from `project_root` to the desired file
  #
  # Returns the absolute url as a String
  def absolute_path(relative_path)
    File.join(@project_root, relative_path)
  end

  class << self
    # Public: Initialize the Configuration Singleton. Must be called before any
    # access to `Configuration.instance` is used.
    #
    # project_root  - The String path to the directory the project is running in
    # file_path     - The String path from `project_root` to the configuration
    #                 file
    def init(project_root, file_path)
      instance = new(project_root, file_path)
      @@instance = instance
    end

    # Public: The Singleton instance of Configuration.
    #<commit_msg>make configuration capable of handling absolute file paths<commit_after>require "json"

# Public: Contains the configuration values set in the configuration.json file.
# Provides a Singleton that can be accessed throughout the application.
class Configuration

  attr_reader :colors_enabled
  attr_reader :region
  attr_reader :policy_suffix
  attr_reader :policy_version
  attr_reader :static_policy_directory
  attr_reader :template_policy_directory
  attr_reader :roles_directory

  # Internal: Constructor. Sets the `instance` variable, which is the access point
  # for the Singleton.
  #
  # project_root  - The String path to the directory the project is running in
  # file_path     - The String path from `project_root` to the configuration
  #                 file
  def initialize(project_root, file_path)
    @project_root = project_root;
    json = JSON.parse(File.read(absolute_path(file_path)))
    @colors_enabled = json["colors-enabled"]
    @policy_suffix = json["policies"]["suffix"]
    @policy_version = json["policies"]["version"]
    @static_policy_directory = absolute_path(json["policies"]["static"]["directory"])
    @template_policy_directory = absolute_path(json["policies"]["templates"]["directory"])
    @roles_directory = absolute_path(json["roles"]["directory"])
    @region = json["region"]
  end

  # Public: Take a path relative to the project root and turn it into an
  # absolute path
  #
  # relative_path - The String path from `project_root` to the desired file
  #
  # Returns the absolute path as a String
  def absolute_path(relative_path)
    if relative_path.start_with?("/")
      relative_path
    else
      File.join(@project_root, relative_path)
    end
  end

  class << self
    # Public: Initialize the Configuration Singleton. Must be called before any
    # access to `Configuration.instance` is used.
    #
    # project_root  - The String path to the directory the project is running in
    # file_path     - The String path from `project_root` to the configuration
    #                 file
    def init(project_root, file_path)
      instance = new(project_root, file_path)
      @@instance = instance
    end

    # Public: The Singleton instance of Configuration.
    #
{'fraction_non_alphanumeric': 0.08227702235538142, 'fraction_numerical': 0.0, 'mean_word_length': 3.8275862068965516, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3187802', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1203, 'n_words': 388}