Class: AbideDevUtils::Ppt::Hiera::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/ppt/hiera.rb

Overview

Represents a Hiera configuration file

Instance Method Summary collapse

Constructor Details

#initialize(path = DEFAULT_CONFIG_FILE, facter_version: DEFAULT_FACTER_VERSION) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 37

def initialize(path = DEFAULT_CONFIG_FILE, facter_version: DEFAULT_FACTER_VERSION)
  @path = File.expand_path(path)
  raise "Hiera config file at path #{@path} not found!" unless File.file?(@path)

  @root_dir = File.dirname(@path)
  @conf = YAML.load_file(File.expand_path(path))
  @by_name_path_store = {}
  #AbideDevUtils::Ppt::Hiera.facter_version = facter_version
  if @conf['defaults'].key?('datadir')
    AbideDevUtils::Ppt::Hiera.default_datadir = File.join(@root_dir, @conf['defaults']['datadir'])
  end
end

Instance Method Details

#default_data_hashObject



66
67
68
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 66

def default_data_hash
  @default_data_hash ||= defaults['data_hash']
end

#default_datadirObject



62
63
64
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 62

def default_datadir
  AbideDevUtils::Ppt::Hiera.default_datadir
end

#defaultsObject



58
59
60
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 58

def defaults
  @defaults ||= @conf['defaults']
end

#hierarchyObject



50
51
52
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 50

def hierarchy
  @hierarchy ||= Hierarchy.new(@conf['hierarchy'], AbideDevUtils::Ppt::Hiera.default_datadir)
end

#local_hiera_files(hierarchy_name: nil) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 70

def local_hiera_files(hierarchy_name: nil)
  if hierarchy_name
    hierarchy.entry_by_name(hierarchy_name).local_files
  else
    hierarchy.entries.map(&:local_files).flatten
  end
end

#local_hiera_files_with_fact(fact_str, value = nil, hierarchy_name: nil) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 78

def local_hiera_files_with_fact(fact_str, value = nil, hierarchy_name: nil)
  if hierarchy_name
    hierarchy.entry_by_name(hierarchy_name).local_files_with_fact(fact_str, value)
  else
    hierarchy.entries.map { |e| e.local_files_with_fact(fact_str, value) }.flatten
  end
end

#local_hiera_files_with_facts(*fact_arrays, hierarchy_name: nil) ⇒ Object



86
87
88
89
90
91
92
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 86

def local_hiera_files_with_facts(*fact_arrays, hierarchy_name: nil)
  if hierarchy_name
    hierarchy.entry_by_name(hierarchy_name).local_files_with_facts(*fact_arrays)
  else
    hierarchy.entries.map { |e| e.local_files_with_fact(*fact_arrays) }.flatten
  end
end

#versionObject



54
55
56
# File 'lib/abide_dev_utils/ppt/hiera.rb', line 54

def version
  @version ||= @conf['version']
end