Module: EasyType::YamlType::ClassMethods

Defined in:
lib/easy_type/yaml_type.rb

Overview

Class methods for yaml based types

Instance Method Summary collapse

Instance Method Details

#config_file(file = nil) ⇒ Object



149
150
151
152
153
154
155
# File 'lib/easy_type/yaml_type.rb', line 149

def config_file(file = nil)
  if file
    @config_file = file
  else
    Pathname.new(@config_file).expand_path
  end
end

#configurationObject



139
140
141
# File 'lib/easy_type/yaml_type.rb', line 139

def configuration
  @configuration
end

#get_raw_resourcesObject



134
135
136
137
# File 'lib/easy_type/yaml_type.rb', line 134

def get_raw_resources
  Puppet.debug "YAML index #{name} "
  resources_from_yaml
end

#read_from_yamlObject



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/easy_type/yaml_type.rb', line 157

def read_from_yaml
  if File.exist?(config_file)
    # The safe version introduced all sorts of issues and
    # the original one doesn't introduce security issues in
    # this contect
    # rubocop: disable Security/YAMLLoad
    data = open(config_file) { |f| YAML.load(f) }
    #
    # If the file is empty or conatains no valid content, data is either nil or false
    # We need to handle that here.
    #
    (data.nil? || data == false) ? {} : data
    # rubocop: enable Security/YAMLLoad
  else
    {}
  end
end

#resources_from_yamlObject



143
144
145
146
147
# File 'lib/easy_type/yaml_type.rb', line 143

def resources_from_yaml
  Puppet.debug 'read_from_yaml '
  @configuration = read_from_yaml
  normalize(@configuration)
end