<commit_before>#
# Copyright 2012-2014 Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'singleton'

module Omnibus
  class Config
    include Cleanroom
    include NullArgumentable
    include Singleton
    include Util

    class << self
      #
      # @param [String] filepath
      #   the path to the config definition to load from disk
      #
      # @return [Config]
      #
      def load(filepath)
        evaluate_file(instance, filepath)
      end

      #
      # @macro default
      #   @method $1(value = NULL)
      #
      # @param [Symbol] key
      #   the name of the configuration value to create
      # @param [Object] default
      #   the default value
      # @param [Proc] block
      #   a block to be called for the default value. If the block is provided,
      #   the +default+ attribute is ignored
      #
      def default(key, default = NullArgumentable::NULL, &block)
        # This is a class method, which delegates to the instance method
        define_singleton_method(key) do |value = NullArgumentable::NULL|
          instance.send(key, value)
        end

        # This is an instance method, but this is a singleton object ;)
        define_method(key) do |value = NullArgumentable::NULL|
          set_or_return(key, value, default, &block)
        end

        # All config options should be avaiable as DSL methods
        expose(key)
      end

      #
      # Check if the configuration includes the given key.
      #
      # @param [Symbol] key
      #
      # @return [true, false]
      #
      def key?(key)
        public_method_defined?(key.to_sym)
      end
      alias_method :has_key?, :key?

      #
      # Reset the current configuration values. This method will unset any
      # "stored" or memorized configuration values.
      #
      # @return [true]
      #
      def reset!
        instance.instance_variables.each do |instance_variable|
          instance.send(:remove_instance_variable, instance_variable)
        end

        true
      end
    end

    #
    # @!group Directory Configuration Parameters
    # --------------------------------------------------

    # The "base" directory where Omnibus will store it's data. Other paths are
    # dynamically computed from this value.
    #
    # - Defaults to +C:\omnibus-ruby+ on Windows
    # - Defaults to +/var/cache/omnibus+ on other platforms
    #
    # @return [String]
    default(:base_dir) do
      if Ohai['platform'] == 'windows'
        'C:/omnibus-ruby'
      else
        '/var/cache/omnibus'
      end
    end

    # The absolute path to the directory on the virtual machine where
    # code will be cached.
    #
    # @return [String]
    default(:cache_dir) { File.join(base_dir, 'cache') }

    # The absolute path to the directory on the virtual machine where
    # git caching will occur and software's will be progressively cached.
    #
    # @return [String]
    default(:git_cache_dir) do
      if defined?(@install_path_cache_dir)
        @install_path_cache_dir
      else
        File.join(base_dir, 'cache', 'git_cache')
      end
    end

    # @deprecated Use {#git_cache_dir} instead.
    #
    # @return [String]
    default(:install_path_cache_dir) do
      Omnibus.logger.deprecated('Config') do
        'Config.install_path_cache_dir. Plase use Config.git_cache_dir instead.'
      end

      git_cache_dir
    end

    # The absolute path to the directory on the virtual machine where
    # source code will be downloaded.
    #
    # @return [String]
    default(:source_dir) { File.join(base_dir, 'src') }

    # The absolute path to the directory on the virtual machine where
    # software will be built.
    #
    # @return [String]
    default(:build_dir) { File.join(base_dir, 'build') }

    # The absolute path to the directory on the virtual machine where
    # packages will be constructed.
    #
    # @return [String]
    default(:package_dir) { File.join(base_dir, 'pkg') }

    # The absolute path to the directory on the virtual machine where
    # packagers will store intermediate packaging products. Some packaging
    # methods (notably fpm) handle this internally so not all packagers will
    # use this setting.
    #<commit_msg>Remove deprecated Config.install_path_cache_dir<commit_after>#
# Copyright 2012-2014 Chef Software, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'singleton'

module Omnibus
  class Config
    include Cleanroom
    include NullArgumentable
    include Singleton
    include Util

    class << self
      #
      # @param [String] filepath
      #   the path to the config definition to load from disk
      #
      # @return [Config]
      #
      def load(filepath)
        evaluate_file(instance, filepath)
      end

      #
      # @macro default
      #   @method $1(value = NULL)
      #
      # @param [Symbol] key
      #   the name of the configuration value to create
      # @param [Object] default
      #   the default value
      # @param [Proc] block
      #   a block to be called for the default value. If the block is provided,
      #   the +default+ attribute is ignored
      #
      def default(key, default = NullArgumentable::NULL, &block)
        # This is a class method, which delegates to the instance method
        define_singleton_method(key) do |value = NullArgumentable::NULL|
          instance.send(key, value)
        end

        # This is an instance method, but this is a singleton object ;)
        define_method(key) do |value = NullArgumentable::NULL|
          set_or_return(key, value, default, &block)
        end

        # All config options should be avaiable as DSL methods
        expose(key)
      end

      #
      # Check if the configuration includes the given key.
      #
      # @param [Symbol] key
      #
      # @return [true, false]
      #
      def key?(key)
        public_method_defined?(key.to_sym)
      end
      alias_method :has_key?, :key?

      #
      # Reset the current configuration values. This method will unset any
      # "stored" or memorized configuration values.
      #
      # @return [true]
      #
      def reset!
        instance.instance_variables.each do |instance_variable|
          instance.send(:remove_instance_variable, instance_variable)
        end

        true
      end
    end

    #
    # @!group Directory Configuration Parameters
    # --------------------------------------------------

    # The "base" directory where Omnibus will store it's data. Other paths are
    # dynamically computed from this value.
    #
    # - Defaults to +C:\omnibus-ruby+ on Windows
    # - Defaults to +/var/cache/omnibus+ on other platforms
    #
    # @return [String]
    default(:base_dir) do
      if Ohai['platform'] == 'windows'
        'C:/omnibus-ruby'
      else
        '/var/cache/omnibus'
      end
    end

    # The absolute path to the directory on the virtual machine where
    # code will be cached.
    #
    # @return [String]
    default(:cache_dir) { File.join(base_dir, 'cache') }

    # The absolute path to the directory on the virtual machine where
    # git caching will occur and software's will be progressively cached.
    #
    # @return [String]
    default(:git_cache_dir) do
      File.join(base_dir, 'cache', 'git_cache')
    end

    # The absolute path to the directory on the virtual machine where
    # source code will be downloaded.
    #
    # @return [String]
    default(:source_dir) { File.join(base_dir, 'src') }

    # The absolute path to the directory on the virtual machine where
    # software will be built.
    #
    # @return [String]
    default(:build_dir) { File.join(base_dir, 'build') }

    # The absolute path to the directory on the virtual machine where
    # packages will be constructed.
    #
    # @return [String]
    default(:package_dir) { File.join(base_dir, 'pkg') }

    # The absolute path to the directory on the virtual machine where
    # packagers will store intermediate packaging products. Some packaging
    # methods (notably fpm) handle this internally so not all packagers will
    # use this setting.
    #
{'fraction_non_alphanumeric': 0.09032258064516129, 'fraction_numerical': 0.0028430836522689994, 'mean_word_length': 2.376153562200074, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843123', 'n_tokens_mistral': 2576, 'n_tokens_neox': 2488, 'n_words': 933}