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 => {
    :rubies      => [ '2.4.1', '2.3.4', '2.2.7', '2.1.10', '2.0.0', '1.9.3' ],
    :version     => '2.3.4',
    :versionfile => '.ruby-version',
    :gemsetfile  => '.ruby-gemset'
  },
  :pyenv => {
    :versions       => ['2.7.14', '2.7.15', '3.6.4', '3.7.1' ],
    :version        => '2.7.14',
    :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:



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

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.



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

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


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

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


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

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