Class: Kafo::PuppetModule
- Inherits:
-
Object
- Object
- Kafo::PuppetModule
- Defined in:
- lib/kafo/puppet_module.rb
Constant Summary collapse
- PRIMARY_GROUP_NAME =
'Parameters'
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#dir_name ⇒ Object
readonly
Returns the value of attribute dir_name.
-
#groups ⇒ Object
readonly
Returns the value of attribute groups.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#manifest_name ⇒ Object
readonly
Returns the value of attribute manifest_name.
-
#manifest_path ⇒ Object
readonly
Returns the value of attribute manifest_path.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#params_class_name ⇒ Object
readonly
Returns the value of attribute params_class_name.
-
#params_path ⇒ Object
readonly
Returns the value of attribute params_path.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(o) ⇒ Object
- #disable ⇒ Object
- #enable ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(identifier, parser = self.class.find_parser, configuration = KafoConfigure.config) ⇒ PuppetModule
constructor
A new instance of PuppetModule.
- #other_parameter_groups ⇒ Object
- #params_hash ⇒ Object
- #parse(builder_klass = ParamBuilder) ⇒ Object
- #primary_parameter_group ⇒ Object
Constructor Details
#initialize(identifier, parser = self.class.find_parser, configuration = KafoConfigure.config) ⇒ PuppetModule
Returns a new instance of PuppetModule.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kafo/puppet_module.rb', line 28 def initialize(identifier, parser = self.class.find_parser, 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 @logger = KafoConfigure.logger @groups = {} @params_path = get_params_path @params_class_name = get_params_class_name @raw_data = nil @enabled = nil end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def class_name @class_name end |
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def configuration @configuration end |
#dir_name ⇒ Object (readonly)
Returns the value of attribute dir_name.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def dir_name @dir_name end |
#groups ⇒ Object (readonly)
Returns the value of attribute groups.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def groups @groups end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def identifier @identifier end |
#manifest_name ⇒ Object (readonly)
Returns the value of attribute manifest_name.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def manifest_name @manifest_name end |
#manifest_path ⇒ Object (readonly)
Returns the value of attribute manifest_path.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def manifest_path @manifest_path end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def name @name end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def params @params end |
#params_class_name ⇒ Object (readonly)
Returns the value of attribute params_class_name.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def params_class_name @params_class_name end |
#params_path ⇒ Object (readonly)
Returns the value of attribute params_path.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def params_path @params_path end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
11 12 13 |
# File 'lib/kafo/puppet_module.rb', line 11 def raw_data @raw_data end |
Class Method Details
.find_parser ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/kafo/puppet_module.rb', line 14 def self.find_parser @parser ||= begin logger = KafoConfigure.logger parser = KafoParsers::Parsers.find_available(:logger => logger) if parser logger.debug "Using Puppet module parser #{parser}" parser else logger.debug "No available Puppet module parser found" :none # prevent continually re-checking end end end |
Instance Method Details
#<=>(o) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/kafo/puppet_module.rb', line 99 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 ⇒ Object
57 58 59 |
# File 'lib/kafo/puppet_module.rb', line 57 def disable @enabled = false end |
#enable ⇒ Object
61 62 63 |
# File 'lib/kafo/puppet_module.rb', line 61 def enable @enabled = true end |
#enabled? ⇒ Boolean
53 54 55 |
# File 'lib/kafo/puppet_module.rb', line 53 def enabled? @enabled.nil? ? @enabled = @configuration.module_enabled?(self) : @enabled end |
#other_parameter_groups ⇒ Object
91 92 93 |
# File 'lib/kafo/puppet_module.rb', line 91 def other_parameter_groups @groups.select { |g| g.formatted_name != PRIMARY_GROUP_NAME } end |
#params_hash ⇒ Object
95 96 97 |
# File 'lib/kafo/puppet_module.rb', line 95 def params_hash Hash[params.map { |param| [param.name, param.value] }] end |
#parse(builder_klass = ParamBuilder) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/kafo/puppet_module.rb', line 65 def parse(builder_klass = ParamBuilder) @raw_data = @parser_cache.get(identifier, manifest_path) if @parser_cache if @raw_data.nil? if @parser.nil? || @parser == :none raise ParserError.new("No Puppet module parser is installed and no cache of the file #{manifest_path} is available. Please check debug logs and install optional dependencies for the parser.") else @raw_data = @parser.parse(manifest_path) end end builder = builder_klass.new(self, @raw_data) builder.validate @params = builder.build_params @groups = builder.build_param_groups(@params) self rescue ConfigurationException => e @logger.fatal "Unable to continue because of: #{e.}" KafoConfigure.exit(:manifest_error) end |
#primary_parameter_group ⇒ Object
87 88 89 |
# File 'lib/kafo/puppet_module.rb', line 87 def primary_parameter_group @groups.detect { |g| g.formatted_name == PRIMARY_GROUP_NAME } || dummy_primary_group end |