Module: Hieracles::Config
Overview
configuration singleton
Instance Attribute Summary collapse
-
#basepath ⇒ Object
readonly
Returns the value of attribute basepath.
-
#classpath ⇒ Object
readonly
Returns the value of attribute classpath.
-
#encpath ⇒ Object
readonly
Returns the value of attribute encpath.
-
#extraparams ⇒ Object
readonly
Returns the value of attribute extraparams.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#hierafile ⇒ Object
readonly
Returns the value of attribute hierafile.
-
#modulepath ⇒ Object
readonly
Returns the value of attribute modulepath.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #defaultconfig ⇒ Object
-
#extract_params(str) ⇒ Object
str is like: something=xxx;another=yyy.
- #initconfig(file) ⇒ Object
- #load(options) ⇒ Object
- #path(what) ⇒ Object
Instance Attribute Details
#basepath ⇒ Object (readonly)
Returns the value of attribute basepath.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def basepath @basepath end |
#classpath ⇒ Object (readonly)
Returns the value of attribute classpath.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def classpath @classpath end |
#encpath ⇒ Object (readonly)
Returns the value of attribute encpath.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def encpath @encpath end |
#extraparams ⇒ Object (readonly)
Returns the value of attribute extraparams.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def extraparams @extraparams end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def format @format end |
#hierafile ⇒ Object (readonly)
Returns the value of attribute hierafile.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def hierafile @hierafile end |
#modulepath ⇒ Object (readonly)
Returns the value of attribute modulepath.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def modulepath @modulepath end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
8 9 10 |
# File 'lib/hieracles/config.rb', line 8 def server @server end |
Instance Method Details
#defaultconfig ⇒ Object
38 39 40 |
# File 'lib/hieracles/config.rb', line 38 def defaultconfig File.join(ENV['HOME'], '.config', 'hieracles', 'config.yml') end |
#extract_params(str) ⇒ Object
str is like: something=xxx;another=yyy
43 44 45 46 47 48 49 |
# File 'lib/hieracles/config.rb', line 43 def extract_params(str) return {} unless str str.split(';').reduce({}) do |a, k| a["#{k[/^[^=]*/]}".to_sym] = k[/[^=]*$/] a end end |
#initconfig(file) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hieracles/config.rb', line 25 def initconfig(file) FileUtils.mkdir_p(File.dirname(file)) File.open(file, 'w') do |f| f.puts '---' f.puts '# uncomment if you use the CGI method for discovery' f.puts '# server: puppetserver.example.com' f.puts 'classpath: manifests/classes/%s.pp' f.puts 'modulepath: modules' f.puts 'encpath: enc' f.puts 'hierafile: hiera.yaml' end end |
#load(options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hieracles/config.rb', line 11 def load() @optionfile = [:config] || defaultconfig @extraparams = extract_params([:params]) initconfig(@optionfile) unless File.exist? @optionfile values = YAML.load_file(@optionfile) @server = values['server'] @classpath = values['classpath'] @modulepath = values['modulepath'] || 'modules' @encpath = [:encpath] || values['encpath'] || 'enc' @basepath = File.([:basepath] || values['basepath'] || '.') @hierafile = [:hierafile] || values['hierafile'] || 'hiera.yaml' @format = ([:format] || values['format'] || 'console').capitalize end |
#path(what) ⇒ Object
51 52 53 |
# File 'lib/hieracles/config.rb', line 51 def path(what) File.join(@basepath, send(what.to_sym)) end |