Class: Tap::Generator::Generators::Config
- Defined in:
- lib/tap/generator/generators/config.rb
Overview
:startdoc::generator a config file generator
Generates a new config file for a task. The configurations, defaults, and documentation is determined from the source file.
Configurations for other types of configurable resources may also be generated. Specify the constant attribute identifying the resource using the ‘type’ flag. This generates a config file for the Root generator:
% tap generate config root --type generator
Constant Summary collapse
- DUMP_NEST_CONFIGS =
Dumps nested configurations.
dump_nest_configs
- DOC_FORMAT =
Dumps configurations as YAML with documentation, used when the doc config is true.
doc_format
- NODOC_FORMAT =
Dumps configurations as YAML without documentation, used when the doc config is false.
nodoc_format
Instance Attribute Summary
Attributes inherited from Base
#prompt_in, #prompt_out, #template_dir
Instance Method Summary collapse
-
#format_block ⇒ Object
A hook to set a formatting block.
-
#lookup(name) ⇒ Object
Lookup the named resource.
- #manifest(m, name, config_name = nil) ⇒ Object
Methods inherited from Base
#action, #directories, #directory, #file, #initialize, #iterate, #log_relative, #on, #path, #process, #set, #template, #template_files
Constructor Details
This class inherits a constructor from Tap::Generator::Base
Instance Method Details
#format_block ⇒ Object
A hook to set a formatting block. By default format_blocks returns DOC_FORMAT or NODOC_FORMAT as per the doc config.
116 117 118 |
# File 'lib/tap/generator/generators/config.rb', line 116 def format_block doc ? DOC_FORMAT : NODOC_FORMAT end |
#lookup(name) ⇒ Object
Lookup the named resource. Lookup happens through the active Env instance, specifically using:
Env.instance[type][name]
Raises an error if the name cannot be resolved to a resource.
83 84 85 86 |
# File 'lib/tap/generator/generators/config.rb', line 83 def lookup(name) env = Tap::Env.instance env[type][name] or raise "unknown #{type}: #{name}" end |
#manifest(m, name, config_name = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/tap/generator/generators/config.rb', line 88 def manifest(m, name, config_name=nil) # setup tasc = lookup(name) config_name ||= tasc.to_s.underscore config_file = path('config', config_name) config_file += ".yml" if File.extname(config_file).empty? # generate the dumps dumps = Configurable::Utils.dump_file( tasc.configurations, config_file, nest, true, &format_block) # now put the dumps to the manifest m.directory(path('config')) dumps.each do |path, content| next if content.empty? && !blanks m.file(path) do |file| file << content end end end |