Module: FalkorLib::Config

Defined in:
lib/falkorlib/config.rb,
lib/falkorlib/git/base.rb,
lib/falkorlib/git/flow.rb,
lib/falkorlib/versioning.rb,
lib/falkorlib/puppet/base.rb,
lib/falkorlib/bootstrap/base.rb,
lib/falkorlib/puppet/modules.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Bootstrap, Git, GitFlow, Puppet, Versioning

Constant Summary collapse

DEFAULTS =

Defaults global settings

{
  :debug          => false,
  :verbose        => false,
  :no_interaction => false,
  :root           => Dir.pwd,
  :config_files   => {
    :local   => '.falkor/config',
    :private => '.falkor/private',
    #:project => '.falkor/project',
  },
  #:custom_cfg   => '.falkorlib.yaml',
  :rvm => {
    # See https://www.ruby-lang.org/en/downloads/branches/ for stable branches
    :rubies      => [ '2.7.0', '2.6.5', '2.5.6', '2.4.9' ],
    :version     => '2.6.5',
    :versionfile => '.ruby-version',
    :gemsetfile  => '.ruby-gemset'
  },
  :pyenv => {
    :versions       => ['2.7.16', '3.7.4' ],
    :version        => '3.7.4',
    :versionfile    => '.python-version',
    :virtualenvfile => '.python-virtualenv',
    :direnvfile     => '.envrc',
    :direnvrc       => File.join( ENV['HOME'], '.config', 'direnv', 'direnvrc')
  },
  :templates => {
    :trashdir => '.Trash',
    :puppet   => {}
  },
  :tokens  => { :code_climate => '' },
  :project => {},
}

Class Method Summary collapse

Class Method Details

.config_file(dir = Dir.pwd, type = :local, options = {}) ⇒ Object

get_or_save ###### wrapper for get and save operations

Raises:



120
121
122
123
124
125
# File 'lib/falkorlib/config.rb', line 120

def config_file(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)
  (options[:file]) ? options[:file] : File.join(path, FalkorLib.config[:config_files][type.to_sym])
end

.defaultObject

Build the default configuration hash, to be used to initiate the default. The hash is built depending on the loaded files.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/falkorlib/config.rb', line 84

def default
  res = FalkorLib::Config::DEFAULTS.clone
  $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.exist?( custom_cfg )
      res.deep_merge!( load_config( custom_cfg ) )
    end
  end
  res
end

.get(dir = Dir.pwd, type = :local, options = {}) ⇒ Object

get ###### Return the { local | private } FalkorLib configuration Supported options:

* :file [string] filename for the local configuration


110
111
112
113
114
115
# File 'lib/falkorlib/config.rb', line 110

def get(dir = Dir.pwd, type = :local, options = {})
  conffile = config_file(dir, type, options)
  res = {}
  res = load_config( conffile ) if File.exist?( conffile )
  res
end

.save(dir = Dir.pwd, config = {}, type = :local, options = {}) ⇒ Object

save ###### save the { local | private } configuration on YAML format Supported options:

* :file [string] filename for the saved configuration
* :no_interaction [boolean]: do not interact


134
135
136
137
138
139
140
141
142
143
# File 'lib/falkorlib/config.rb', line 134

def save(dir = Dir.pwd, config = {}, type = :local, options = {})
  conffile = config_file(dir, type, options)
  confdir  = File.dirname( conffile )
  unless File.directory?( confdir )
    warning "about to create the configuration directory #{confdir}"
    really_continue?  unless options[:no_interaction]
    run %( mkdir -p #{confdir} )
  end
  store_config(conffile, config, options)
end