Class: MofaYml

Inherits:
Object
  • Object
show all
Defined in:
lib/mofa/mofa_yml.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMofaYml

Returns a new instance of MofaYml.



5
6
7
# File 'lib/mofa/mofa_yml.rb', line 5

def initialize
  @yml = {}
end

Instance Attribute Details

#cookbookObject

Returns the value of attribute cookbook.



2
3
4
# File 'lib/mofa/mofa_yml.rb', line 2

def cookbook
  @cookbook
end

#ymlObject

Returns the value of attribute yml.



3
4
5
# File 'lib/mofa/mofa_yml.rb', line 3

def yml
  @yml
end

Class Method Details

.load_from_file(path_to_mofayml, cookbook) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/mofa/mofa_yml.rb', line 9

def self.load_from_file(path_to_mofayml, cookbook)
  mfyml = MofaYml.new
  mfyml.cookbook = cookbook
  # puts "Loading .mofa.yml/.mofa.local.yml from path #{path_to_mofayml}..."
  if File.exist?(path_to_mofayml)
    mfyml.parse_and_load(path_to_mofayml)
  end
  mfyml
end

Instance Method Details

#get_attr_for_role(role_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mofa/mofa_yml.rb', line 19

def get_attr_for_role(role_name)
  attr = {}
  if @yml.key?('roles') # && @yml['roles'].kind_of?(Array)
    @yml['roles'].each do |role|
      if role.key?('name') && role['name'] == role_name
        if role.key?('attributes')
          attr = role['attributes']
        end
      end
    end
  end
  attr
end

#parse_and_load(path_to_mofayml) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/mofa/mofa_yml.rb', line 33

def parse_and_load(path_to_mofayml)
  # for now only __ENV_COOKBOOK__ for cookbook name is supported
  file_contents = File.read(path_to_mofayml)
  file_contents.gsub!(/__ENV_COOKBOOK__/, @cookbook.name)
  @yml = YAML.load(file_contents)
  # puts "YAML is now:"
  # puts @yml.inspect
  @yml
end