Class: Tap::Generator::Generators::ConfigGenerator

Inherits:
Base show all
Defined in:
lib/tap/generator/generators/config/config_generator.rb

Overview

:startdoc: Tap::Generator::Generators::ConfigGenerator::generator a config file for a task

Generates a new config file for a task. The configurations, defaults, and documentation is determined from the task source file.

Constant Summary

Constants inherited from Task

Task::DEFAULT_HELP_TEMPLATE

Instance Attribute Summary

Attributes inherited from Base

#prompt_in, #prompt_out, #template_dir

Attributes inherited from Task

#name

Attributes included from Support::Executable

#app, #batch, #dependencies, #method_name, #on_complete_block

Instance Method Summary collapse

Methods inherited from Base

#directories, #directory, #file, #initialize, #iterate, #log_relative, #process, #template_files

Methods inherited from Task

execute, help, inherited, #initialize, #initialize_batch_obj, #inspect, instance, intern, load, #log, parse, parse!, #process, #to_s, use

Methods included from Support::Executable

#_execute, #batch_index, #batch_with, #batched?, #check_terminate, #depends_on, #enq, #execute, #fork, initialize, #initialize_batch_obj, #merge, #on_complete, #reset_dependencies, #resolve_dependencies, #sequence, #switch, #sync_merge, #unbatched_depends_on, #unbatched_enq, #unbatched_on_complete

Constructor Details

This class inherits a constructor from Tap::Generator::Base

Instance Method Details

#dump(m, path, configurations, &block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tap/generator/generators/config/config_generator.rb', line 28

def dump(m, path, configurations, &block)
  non_nested_configurations = configurations.to_a.sort_by do |(key, config)|
    config.attributes[:declaration_order] || 0
  end.collect do |(key, config)|
    default = config.default(false)
    
    if default.kind_of?(Configurable::DelegateHash)
      # nest nested configs

      dump(m, File.join(path, key), default, &block)
      nil
    else
      # duplicate config so that any changes to it

      # during templation will not propogate back

      # into configurations

      [key, config.dup]
    end
  end.compact
  
  if block_given?
    yield(non_nested_configurations)
  end
  
  m.file "#{path}.yml" do |file|
    templater = Tap::Support::Templater.new(template)
    templater.configurations = non_nested_configurations
    file << templater.build
  end
end

#envObject



11
12
13
# File 'lib/tap/generator/generators/config/config_generator.rb', line 11

def env
  Tap::Env.instance
end

#manifest(m, name, config_name = name) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/tap/generator/generators/config/config_generator.rb', line 15

def manifest(m, name, config_name=name)
  const = env.tasks.search(name) or raise "unknown task: #{name}"
  task_class = const.constantize or raise "unknown task: #{name}"
  
  m.directory app['config']
  dump(m, app.filepath('config', config_name), task_class.configurations)
end

#templateObject



23
24
25
26
# File 'lib/tap/generator/generators/config/config_generator.rb', line 23

def template
  path = File.expand_path(doc ? 'doc.erb' : 'nodoc.erb', template_dir)
  File.read(path)
end