Class: Kitchenplan::Config
- Inherits:
-
Object
- Object
- Kitchenplan::Config
- Defined in:
- lib/kitchenplan/config.rb
Instance Attribute Summary collapse
-
#default_config ⇒ Object
readonly
Returns the value of attribute default_config.
-
#group_configs ⇒ Object
readonly
Returns the value of attribute group_configs.
-
#people_config ⇒ Object
readonly
Returns the value of attribute people_config.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#system_config ⇒ Object
readonly
Returns the value of attribute system_config.
Instance Method Summary collapse
- #config ⇒ Object
- #detect_platform ⇒ Object
- #hardware_model ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #parse_default_config ⇒ Object
- #parse_group_config(group) ⇒ Object
- #parse_group_configs(group = (( @default_config['groups'] || [] ) | ( @people_config['groups'] || [] ))) ⇒ Object
- #parse_people_config ⇒ Object
- #parse_system_config ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
17 18 19 20 21 22 23 |
# File 'lib/kitchenplan/config.rb', line 17 def initialize self.detect_platform self.parse_default_config self.parse_people_config self.parse_system_config self.parse_group_configs end |
Instance Attribute Details
#default_config ⇒ Object (readonly)
Returns the value of attribute default_config.
12 13 14 |
# File 'lib/kitchenplan/config.rb', line 12 def default_config @default_config end |
#group_configs ⇒ Object (readonly)
Returns the value of attribute group_configs.
15 16 17 |
# File 'lib/kitchenplan/config.rb', line 15 def group_configs @group_configs end |
#people_config ⇒ Object (readonly)
Returns the value of attribute people_config.
13 14 15 |
# File 'lib/kitchenplan/config.rb', line 13 def people_config @people_config end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
11 12 13 |
# File 'lib/kitchenplan/config.rb', line 11 def platform @platform end |
#system_config ⇒ Object (readonly)
Returns the value of attribute system_config.
14 15 16 |
# File 'lib/kitchenplan/config.rb', line 14 def system_config @system_config end |
Instance Method Details
#config ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/kitchenplan/config.rb', line 71 def config config = {} config['recipes'] = [] config['recipes'] |= hash_path(@default_config, 'recipes', 'global') || [] config['recipes'] |= hash_path(@default_config, 'recipes', @platform) || [] @group_configs.each do |group_name, group_config| config['recipes'] |= hash_path(group_config, 'recipes', 'global') || [] config['recipes'] |= hash_path(group_config, 'recipes', @platform) || [] end people_recipes = @people_config['recipes'] || {} config['recipes'] |= people_recipes['global'] || [] config['recipes'] |= people_recipes[@platform] || [] system_recipes = @system_config['recipes'] || {} config['recipes'] |= system_recipes['global'] || [] config['recipes'] |= system_recipes[@platform] || [] # First take the attributes from default.yml config['attributes'] = {} config['attributes'].deep_merge!(@default_config['attributes'] || {}) { |key, old, new| Array.wrap(old) + Array.wrap(new) } # then override and extend them with the group attributes @group_configs.each do |group_name, group_config| config['attributes'].deep_merge!(group_config['attributes']) { |key, old, new| Array.wrap(old) + Array.wrap(new) } unless group_config['attributes'].nil? end # then override and extend them with the people attributes people_attributes = @people_config['attributes'] || {} config['attributes'].deep_merge!(people_attributes) { |key, old, new| Array.wrap(old) + Array.wrap(new) } # lastly override from the system files system_attributes = @system_config['attributes'] || {} config['attributes'].deep_merge!(system_attributes) { |key, old, new| Array.wrap(old) + Array.wrap(new) } config end |
#detect_platform ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/kitchenplan/config.rb', line 25 def detect_platform #ohai = Ohai::System.new #ohai.require_plugin('os') #ohai.require_plugin('platform') #@platform = ohai[:platform_family] @platform = 'mac_os_x' # We only support osx at the moment, and it saves a large dependency end |
#hardware_model ⇒ Object
33 34 35 |
# File 'lib/kitchenplan/config.rb', line 33 def hardware_model `sysctl -n hw.model | tr -d '\n'` end |
#parse_default_config ⇒ Object
37 38 39 40 |
# File 'lib/kitchenplan/config.rb', line 37 def parse_default_config default_config_path = 'config/default.yml' @default_config = (YAML.load(ERB.new(File.read(default_config_path)).result) if File.exist?(default_config_path)) || {} end |
#parse_group_config(group) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/kitchenplan/config.rb', line 60 def parse_group_config(group) unless @group_configs[group] group_config_path = "config/groups/#{group}.yml" @group_configs[group] = (YAML.load(ERB.new(File.read(group_config_path)).result) if File.exist?(group_config_path)) || {} defined_groups = @group_configs[group]['groups'] if defined_groups self.parse_group_configs(defined_groups) end end end |
#parse_group_configs(group = (( @default_config['groups'] || [] ) | ( @people_config['groups'] || [] ))) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/kitchenplan/config.rb', line 52 def parse_group_configs(group = (( @default_config['groups'] || [] ) | ( @people_config['groups'] || [] ))) @group_configs = @group_configs || {} defined_groups = group || [] defined_groups.each do |group| self.parse_group_config(group) end end |
#parse_people_config ⇒ Object
42 43 44 45 |
# File 'lib/kitchenplan/config.rb', line 42 def parse_people_config people_config_path = "config/people/#{Etc.getlogin}.yml" @people_config = (YAML.load(ERB.new(File.read(people_config_path)).result) if File.exist?(people_config_path)) || {} end |
#parse_system_config ⇒ Object
47 48 49 50 |
# File 'lib/kitchenplan/config.rb', line 47 def parse_system_config system_config_path = "config/system/#{hardware_model}.yml" @system_config = (YAML.load(ERB.new(File.read(system_config_path)).result) if File.exist?(system_config_path)) || {} end |