Class: Puppet::Module::Tool::Applications::Generator

Inherits:
Application
  • Object
show all
Defined in:
lib/puppet/module/tool/applications/generator.rb

Defined Under Namespace

Classes: DirectoryNode, FileNode, Node, ParsedFileNode

Instance Attribute Summary

Attributes inherited from Application

#options

Instance Method Summary collapse

Methods inherited from Application

#discuss, #load_modulefile!, #metadata, #parse_filename!, #repository, run

Methods included from Utils::Interrogation

#confirms?, #header, #prompt, #say, #subheader

Constructor Details

#initialize(full_name, options) ⇒ Generator

Returns a new instance of Generator.



10
11
12
13
14
15
16
17
# File 'lib/puppet/module/tool/applications/generator.rb', line 10

def initialize(full_name, options)
  begin
    @metadata = Metadata.new(:full_name => full_name)
  rescue ArgumentError
    abort "Could not generate directory #{full_name.inspect}, you must specify a dash-separated username and module name."
  end
  super(options)
end

Instance Method Details

#destinationObject



43
44
45
# File 'lib/puppet/module/tool/applications/generator.rb', line 43

def destination
  @destination ||= Pathname.new(@metadata.dashed_name)
end

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/puppet/module/tool/applications/generator.rb', line 23

def run
  if destination.directory?
    abort "#{destination} already exists."
  end
  header "Generating module at #{Dir.pwd}/#{@metadata.dashed_name}"
  skeleton.path.find do |path|
    if path == skeleton
      destination.mkpath
    else
      node = Node.on(path, self)
      if node
        node.install!
        say node.target
      else
        say "Could not generate from #{path}"
      end
    end
  end
end

#skeletonObject



19
20
21
# File 'lib/puppet/module/tool/applications/generator.rb', line 19

def skeleton
  @skeleton ||= Skeleton.new
end