Module: Hiera::Util
- Defined in:
- lib/hiera/util.rb
Class Method Summary collapse
- .code_dir ⇒ Object
- .common_appdata ⇒ Object
- .config_dir ⇒ Object
- .file_alt_separator ⇒ Object
- .microsoft_windows? ⇒ Boolean
- .posix? ⇒ Boolean
- .split_key(key) ⇒ Object
- .var_dir ⇒ Object
Class Method Details
.code_dir ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/hiera/util.rb', line 35 def code_dir if microsoft_windows? File.join(common_appdata, 'PuppetLabs', 'code') else '/etc/puppetlabs/code' end end |
.common_appdata ⇒ Object
51 52 53 |
# File 'lib/hiera/util.rb', line 51 def common_appdata Dir::COMMON_APPDATA end |
.config_dir ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/hiera/util.rb', line 27 def config_dir if microsoft_windows? File.join(common_appdata, 'PuppetLabs', 'puppet', 'etc') else '/etc/puppetlabs/puppet' end end |
.file_alt_separator ⇒ Object
47 48 49 |
# File 'lib/hiera/util.rb', line 47 def file_alt_separator File::ALT_SEPARATOR end |
.microsoft_windows? ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hiera/util.rb', line 15 def microsoft_windows? return false unless file_alt_separator begin require 'win32/dir' true rescue LoadError => err warn "Cannot run on Microsoft Windows without the win32-dir gem: #{err}" false end end |
.posix? ⇒ Boolean
10 11 12 13 |
# File 'lib/hiera/util.rb', line 10 def posix? require 'etc' Etc.getpwuid(0) != nil end |
.split_key(key) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hiera/util.rb', line 55 def split_key(key) segments = key.split(/(?:"([^"]+)"|'([^']+)'|([^'".]+))/) if segments.empty? # Only happens if the original key was an empty string '' elsif segments.shift == '' count = segments.size raise yield('Syntax error') unless count > 0 segments.keep_if { |seg| seg != '.' } raise yield('Syntax error') unless segments.size * 2 == count + 1 segments else raise yield('Syntax error') end end |
.var_dir ⇒ Object
43 44 45 |
# File 'lib/hiera/util.rb', line 43 def var_dir File.join(code_dir, 'environments' , '%{environment}' , 'hieradata') end |