<commit_before># -*- encoding: utf-8 -*-
################################################################################
# Time-stamp: <Jeu 2015-02-12 11:07 svarrette>
################################################################################
# FalkorLib Configuration
#
# Resources:
#  * https://github.com/markbates/cover_me/blob/master/lib/cover_me/config.rb
################################################################################
require "falkorlib"

require "configatron"
require "configatron/store"
require "deep_merge"

module FalkorLib #:nodoc:

    class << self
        # Yields up a configuration object when given a block.
        # Without a block it just returns the configuration object.
        # Uses Configatron under the covers.
        #
        # Example:
        #   FalkorLib.config do |c|
        #     c.foo = :bar
        #   end
        #
        #   FalkorLib.config.foo # => :bar
        def config(&block)
            yield configuration if block_given?
            configuration
        end

        ## initiate the configuration (with default value) if needed
        def configuration
            @config ||= Configatron::Store.new(options = FalkorLib::Config.default)
        end
    end


    module Config #:nodoc:
        # Defaults global settings
        DEFAULTS = {
                    :debug        => false,
                    :verbose      => false,
                    :root         => Dir.pwd,
                    :config_files => {
                                      :local   => '.falkor/config',
                                      :private => '.falkor/private',
                                      #:project => '.falkor/project',
                                     },
                    #:custom_cfg   => '.falkorlib.yaml',
                    :rvm => {
                             :rubies      => [ '1.9.3', '2.0.0', '2.1.0'],
                             :version     => '1.9.3',
                             :versionfile => '.ruby-version',
                             :gemsetfile  => '.ruby-gemset'
                            },
                    :templates => {
                                   :trashdir => '.Trash',
                                   :puppet   => {}
                                  },
                    :tokens  => { :code_climate => '' },
                    :project => {}
                   }

        module_function

        ## Build the default configuration hash, to be used to initiate the default.
        # The hash is built depending on the loaded files.
        def default
            res = FalkorLib::Config::DEFAULTS
            $LOADED_FEATURES.each do |path|
                res[:git]        = FalkorLib::Config::Git::DEFAULTS        if path.include?('lib/falkorlib/git.rb')
                res[:gitflow]    = FalkorLib::Config::GitFlow::DEFAULTS    if path.include?('lib/falkorlib/git.rb')
                res[:versioning] = FalkorLib::Config::Versioning::DEFAULTS if path.include?('lib/falkorlib/versioning.rb')
                if path.include?('lib/falkorlib/puppet.rb')
                    res[:puppet]     = FalkorLib::Config::Puppet::DEFAULTS
                    res[:templates][:puppet][:modules] = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata]
                end
            end
            # Check the potential local customizations
            [:local, :private].each do |type|
                custom_cfg = File.join( res[:root], res[:config_files][type.to_sym])
                if File.exists?( custom_cfg )
                    res.deep_merge!( load_config( custom_cfg ) )
                end
            end
            res
        end

        ###### load_project ######
        # Return the local project configuration
        ##
        def load_project(dir = Dir.pwd, options = {})
            project_file = options[:file] ? options[:file] : FalkorLib.config[:config_files][:local]
            path = normalized_path(dir)
            path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
            res = {}
            #if File.exists?( )
        end # load_project


    end



end # module FalkorLib<commit_msg>add get / save methods for the [local] customization of the configuration<commit_after># -*- encoding: utf-8 -*-
################################################################################
# Time-stamp: <Mar 2015-02-24 11:58 svarrette>
################################################################################
# FalkorLib Configuration
#
# Resources:
#  * https://github.com/markbates/cover_me/blob/master/lib/cover_me/config.rb
################################################################################
require "falkorlib"

require "configatron"
require "configatron/store"
require "deep_merge"

module FalkorLib #:nodoc:

    class << self
        # Yields up a configuration object when given a block.
        # Without a block it just returns the configuration object.
        # Uses Configatron under the covers.
        #
        # Example:
        #   FalkorLib.config do |c|
        #     c.foo = :bar
        #   end
        #
        #   FalkorLib.config.foo # => :bar
        def config(&block)
            yield configuration if block_given?
            configuration
        end

        ## initiate the configuration (with default value) if needed
        def configuration
            @config ||= Configatron::Store.new(options = FalkorLib::Config.default)
        end
    end


    module Config #:nodoc:
        # Defaults global settings
        DEFAULTS = {
                    :debug        => false,
                    :verbose      => false,
                    :root         => Dir.pwd,
                    :config_files => {
                                      :local   => '.falkor/config',
                                      :private => '.falkor/private',
                                      #:project => '.falkor/project',
                                     },
                    #:custom_cfg   => '.falkorlib.yaml',
                    :rvm => {
                             :rubies      => [ '1.9.3', '2.0.0', '2.1.0'],
                             :version     => '1.9.3',
                             :versionfile => '.ruby-version',
                             :gemsetfile  => '.ruby-gemset'
                            },
                    :templates => {
                                   :trashdir => '.Trash',
                                   :puppet   => {}
                                  },
                    :tokens  => { :code_climate => '' },
                    :project => {}
                   }

        module_function

        ## Build the default configuration hash, to be used to initiate the default.
        # The hash is built depending on the loaded files.
        def default
            res = FalkorLib::Config::DEFAULTS
            $LOADED_FEATURES.each do |path|
                res[:git]        = FalkorLib::Config::Git::DEFAULTS        if path.include?('lib/falkorlib/git.rb')
                res[:gitflow]    = FalkorLib::Config::GitFlow::DEFAULTS    if path.include?('lib/falkorlib/git.rb')
                res[:versioning] = FalkorLib::Config::Versioning::DEFAULTS if path.include?('lib/falkorlib/versioning.rb')
                if path.include?('lib/falkorlib/puppet.rb')
                    res[:puppet]     = FalkorLib::Config::Puppet::DEFAULTS
                    res[:templates][:puppet][:modules] = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata]
                end
            end
            # Check the potential local customizations
            [:local, :private].each do |type|
                custom_cfg = File.join( res[:root], res[:config_files][type.to_sym])
                if File.exists?( custom_cfg )
                    res.deep_merge!( load_config( custom_cfg ) )
                end
            end
            res
        end

        ###### get ######
        # Return the { local | private } FalkorLib configuration
        # Supported options:
        #  * :file [string] filename for the local configuration
        ##
        def get(dir = Dir.pwd, type = :local, options = {})
            path = normalized_path(dir)
            path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
            raise FalkorLib::Error, "Wrong FalkorLib configuration type" unless FalkorLib.config[:config_files].keys.include?( type.to_sym)
            local_config_file = options[:file] ? options[:file] : File.join(path, FalkorLib.config[:config_files][type.to_sym])
            res = {}
            res = load_config( local_config_file ) if File.exists?( local_config_file )
            res
        end # get

        ###### save ######
        # save the { local | private } configuration on YAML format
        # Supported options:
        #  * :file [string] filename for the saved configuration
        ##
        def save(dir = Dir.pwd, config = {}, type = :local, options = {})
            path = normalized_path(dir)
            path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
            raise FalkorLib::Error, "Wrong FalkorLib configuration type"unless  FalkorLib.config[:config_files].keys.include?( type.to_sym)
            conffile = options[:file] ? options[:file] : File.join(path, FalkorLib.config[:config_files][type.to_sym])
            confdir  = File.dirname( conffile )
            unless File.directory?( confdir )
                really_continue? "about to create the configuration directory #{confdir}"
                run %{ mkdir -p #{confdir} }
            end
            store_config(conffile, config)
        end # save

    end
end # module FalkorLib
{'fraction_non_alphanumeric': 0.15785140975509365, 'fraction_numerical': 0.005145091582630171, 'mean_word_length': 1.5979684576316493, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '479011', 'n_tokens_mistral': 2618, 'n_tokens_neox': 2475, 'n_words': 545}