Class: CMDB::Rewriter
- Inherits:
-
Object
- Object
- CMDB::Rewriter
- Defined in:
- lib/cmdb/rewriter.rb
Overview
Tool that visits every file in a hierarchy and rewrites its references to CMDB inputs.
References look like <<name.of.key>> and may be replaced with a scalar value or an array depending on the type of the input value.
Instance Attribute Summary collapse
-
#missing_keys ⇒ Object
readonly
Returns the value of attribute missing_keys.
Instance Method Summary collapse
-
#initialize(config_dir) ⇒ Rewriter
constructor
Create a new shim to rewrite config files in a chosen dir and all subdirs.
-
#rewrite(cmdb) ⇒ Integer
Substitute CMDB input values into config files whenever a replacement token is encountered.
- #save ⇒ Object
Constructor Details
#initialize(config_dir) ⇒ Rewriter
Create a new shim to rewrite config files in a chosen dir and all subdirs. config_dir is transformed into an absolute path (if it isn’t already) before any rewrite operations occur.
18 19 20 21 |
# File 'lib/cmdb/rewriter.rb', line 18 def initialize(config_dir) @dir = File.(config_dir) @rewriters = [] end |
Instance Attribute Details
#missing_keys ⇒ Object (readonly)
Returns the value of attribute missing_keys.
11 12 13 |
# File 'lib/cmdb/rewriter.rb', line 11 def missing_keys @missing_keys end |
Instance Method Details
#rewrite(cmdb) ⇒ Integer
Substitute CMDB input values into config files whenever a replacement token is encountered.
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cmdb/rewriter.rb', line 27 def rewrite(cmdb) raise Errno::ENOENT.new(@dir) unless File.directory?(@dir) visit(@dir) total = 0 @rewriters.each { |rw| total += rw.rewrite(cmdb) } @missing_keys = @rewriters.map(&:missing_keys).flatten.uniq.sort total end |
#save ⇒ Object
39 40 41 42 |
# File 'lib/cmdb/rewriter.rb', line 39 def save @rewriters.each(&:save) true end |