<commit_before>require 'thread'
require 'lotus/utils/hash'

module Lotus
  class Environment
    RACK_ENV    = 'RACK_ENV'.freeze
    LOTUS_ENV   = 'LOTUS_ENV'.freeze
    DEFAULT_ENV = 'development'.freeze

    LOTUS_HOST      = 'LOTUS_HOST'.freeze
    DEFAULT_HOST    = 'localhost'.freeze
    LISTEN_ALL_HOST = '0.0.0.0'.freeze

    LOTUS_PORT   = 'LOTUS_PORT'.freeze
    DEFAULT_PORT = 2300

    DEFAULT_CONFIG       = 'config.ru'.freeze
    DEFAULT_APPLICATIONS = 'config/applications'.freeze

    def initialize(options = {})
      @options = Utils::Hash.new(options).symbolize!.freeze
      @mutex   = Mutex.new
      @mutex.synchronize { set_env_vars! }
    end

    def environment
      @environment ||= ENV[LOTUS_ENV] || ENV[RACK_ENV] || DEFAULT_ENV
    end

    def host
      @host ||= @options.fetch(:host) {
        ENV[LOTUS_HOST] || default_host
      }
    end

    def port
      @port ||= @options.fetch(:port) { ENV[LOTUS_PORT] || DEFAULT_PORT }.to_i
    end

    def config
      @options.fetch(:config) { DEFAULT_CONFIG }
    end

    def applications
      @options.fetch(:applications) { DEFAULT_APPLICATIONS }
    end

    def to_options<commit_msg>Adding a some documentation to Environment<commit_after>require 'thread'
require 'lotus/utils/hash'

module Lotus
  # Define and expose information about the Lotus environment.
  #
  # @since 0.1.0
  class Environment
    RACK_ENV    = 'RACK_ENV'.freeze
    LOTUS_ENV   = 'LOTUS_ENV'.freeze
    DEFAULT_ENV = 'development'.freeze

    LOTUS_HOST      = 'LOTUS_HOST'.freeze
    DEFAULT_HOST    = 'localhost'.freeze
    LISTEN_ALL_HOST = '0.0.0.0'.freeze

    LOTUS_PORT   = 'LOTUS_PORT'.freeze
    DEFAULT_PORT = 2300

    DEFAULT_CONFIG       = 'config.ru'.freeze
    DEFAULT_APPLICATIONS = 'config/applications'.freeze

    # @param options [Hash] override default options for various environment attributes
    def initialize(options = {})
      @options = Utils::Hash.new(options).symbolize!.freeze
      @mutex   = Mutex.new
      @mutex.synchronize { set_env_vars! }
    end

    # In what context are the applications running?
    #
    # @return [String]
    def environment
      @environment ||= ENV[LOTUS_ENV] || ENV[RACK_ENV] || DEFAULT_ENV
    end

    # The HTTP host name
    #
    # @return [String]
    def host
      @host ||= @options.fetch(:host) {
        ENV[LOTUS_HOST] || default_host
      }
    end

    # The HTTP port
    #
    # @return [Integer]
    def port
      @port ||= @options.fetch(:port) { ENV[LOTUS_PORT] || DEFAULT_PORT }.to_i
    end

    # Filename of the Rack configuration file
    #
    # @return [String] filename with the Rack configuration
    def config
      @options.fetch(:config) { DEFAULT_CONFIG }
    end

    # @return [String] path to directory that contains registered applications
    def applications
      @options.fetch(:applications) { DEFAULT_APPLICATIONS }
    end

    # @return [Lotus::Utils::Hash]
    def to_options
{'fraction_non_alphanumeric': 0.10487144790257104, 'fraction_numerical': 0.0064276048714479025, 'mean_word_length': 2.747782002534854, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '205176', 'n_tokens_mistral': 992, 'n_tokens_neox': 965, 'n_words': 210}