# File lib/kafo/puppet_module.rb, line 67 def primary_parameter_group @groups.detect { |g| g.formatted_name == PRIMARY_GROUP_NAME } || dummy_primary_group end
class Kafo::PuppetModule
Constants
- PRIMARY_GROUP_NAME
Attributes
class_name[R]
configuration[R]
dir_name[R]
groups[R]
identifier[R]
manifest_name[R]
manifest_path[R]
name[R]
params[R]
params_class_name[R]
params_path[R]
raw_data[R]
Public Class Methods
new(identifier, parser = KafoParsers::PuppetModuleParser, configuration = KafoConfigure.config)
click to toggle source
# File lib/kafo/puppet_module.rb, line 14 def initialize(identifier, parser = KafoParsers::PuppetModuleParser, configuration = KafoConfigure.config) @identifier = identifier @configuration = configuration @name = get_name @dir_name = get_dir_name @manifest_name = get_manifest_name @class_name = get_class_name @params = [] if @configuration.module_dirs.count == 1 module_dir = @configuration.module_dirs.first else module_dir = @configuration.module_dirs.find { |dir| File.exists?(File.join(dir, module_manifest_path)) } || warn("Manifest #{module_manifest_path} was not found in #{@configuration.module_dirs.join(', ')}") end @manifest_path = File.join(module_dir, module_manifest_path) @parser = parser @parser_cache = @configuration.parser_cache @validations = [] @logger = KafoConfigure.logger @groups = {} @params_path = get_params_path @params_class_name = get_params_class_name end
Public Instance Methods
<=>(o)
click to toggle source
# File lib/kafo/puppet_module.rb, line 89 def <=> o @configuration.app[:low_priority_modules].each do |module_name| return 1 if self.name.include?(module_name) && !o.name.include?(module_name) return -1 if !self.name.include?(module_name) && o.name.include?(module_name) if self.name.include?(module_name) && o.name.include?(module_name) return self.name.sub(/.*#{module_name}/, '') <=> o.name.sub(/.*#{module_name}/, '') end end self.name <=> o.name end
disable()
click to toggle source
# File lib/kafo/puppet_module.rb, line 42 def disable @enabled = false end
enable()
click to toggle source
# File lib/kafo/puppet_module.rb, line 46 def enable @enabled = true end
enabled?()
click to toggle source
# File lib/kafo/puppet_module.rb, line 38 def enabled? @enabled.nil? ? @enabled = @configuration.module_enabled?(self) : @enabled end
other_parameter_groups()
click to toggle source
# File lib/kafo/puppet_module.rb, line 71 def other_parameter_groups @groups.select { |g| g.formatted_name != PRIMARY_GROUP_NAME } end
params_hash()
click to toggle source
# File lib/kafo/puppet_module.rb, line 85 def params_hash Hash[params.map { |param| [param.name, param.value] }] end
parse(builder_klass = ParamBuilder)
click to toggle source
# File lib/kafo/puppet_module.rb, line 50 def parse(builder_klass = ParamBuilder) @params = [] @raw_data = @parser_cache.get(identifier, manifest_path) if @parser_cache @raw_data ||= @parser.parse(manifest_path) builder = builder_klass.new(self, @raw_data) @validations = @raw_data[:validations] builder.validate @params = builder.build_params @groups = builder.build_param_groups(@params) self rescue ConfigurationException => e @logger.fatal "Unable to continue because of: #{e.message}" KafoConfigure.exit(:manifest_error) end
primary_parameter_group()
click to toggle source
validations(param = nil)
click to toggle source
# File lib/kafo/puppet_module.rb, line 75 def validations(param = nil) if param.nil? @validations else @validations.select do |validation| validation.arguments.map(&:to_s).include?("$#{param.name}") end end end
Private Instance Methods
default_params_path()
click to toggle source
# File lib/kafo/puppet_module.rb, line 149 def default_params_path "#{dir_name}/manifests/#{get_params_name}.pp" end
dummy_primary_group()
click to toggle source
used when user haven't specified any primary group by name, we create a new group that holds all other groups as children, if we have no other groups (no children) we set all parameters that this module hold
# File lib/kafo/puppet_module.rb, line 106 def dummy_primary_group group = ParamGroup.new(PRIMARY_GROUP_NAME) other_parameter_groups.each { |child| group.add_child(child) } @params.each { |p| group.add_param(p) } if group.children.empty? group end
get_class_name()
click to toggle source
# File lib/kafo/puppet_module.rb, line 128 def get_class_name manifest_name == 'init' ? name : "#{dir_name}::#{manifest_name.gsub('/', '::')}" end
get_dir_name()
click to toggle source
custom module directory name
# File lib/kafo/puppet_module.rb, line 119 def get_dir_name mapping[identifier].nil? ? name : mapping[identifier][:dir_name] end
get_manifest_name()
click to toggle source
custom manifest filename without .pp extension
# File lib/kafo/puppet_module.rb, line 124 def get_manifest_name mapping[identifier].nil? ? 'init' : mapping[identifier][:manifest_name] end
get_name()
click to toggle source
# File lib/kafo/puppet_module.rb, line 153 def get_name identifier.gsub('::', '_') end
get_params_class_name()
click to toggle source
# File lib/kafo/puppet_module.rb, line 141 def get_params_class_name name_to_class_name(get_params_name) end
get_params_name()
click to toggle source
# File lib/kafo/puppet_module.rb, line 136 def get_params_name default = 'params' mapping[identifier].nil? ? default : (mapping[identifier][:params_name] || default) end
get_params_path()
click to toggle source
# File lib/kafo/puppet_module.rb, line 132 def get_params_path mapping[identifier].nil? ? default_params_path : (mapping[identifier][:params_path] || default_params_path) end
mapping()
click to toggle source
mapping from configuration with stringified keys
# File lib/kafo/puppet_module.rb, line 114 def mapping @mapping ||= Hash[@configuration.app[:mapping].map { |k, v| [k.to_s, v] }] end
module_manifest_path()
click to toggle source
# File lib/kafo/puppet_module.rb, line 145 def module_manifest_path "#{dir_name}/manifests/#{manifest_name}.pp" end
name_to_class_name(name)
click to toggle source
# File lib/kafo/puppet_module.rb, line 157 def name_to_class_name(name) name.gsub('/', '::') end