Class: Puppet::ModuleTool::Applications::Generator

Inherits:
Application show all
Defined in:
lib/vendor/puppet/module_tool/applications/generator.rb

Defined Under Namespace

Classes: DirectoryNode, FileNode, Node, ParsedFileNode

Constant Summary

Constants inherited from Application

Application::DOCPATTERN

Constants included from Util

Util::AbsolutePathPosix, Util::AbsolutePathWindows

Instance Attribute Summary

Attributes inherited from Application

#command_line, #options

Instance Method Summary collapse

Methods inherited from Application

[], banner, clear!, clear?, #configure_indirector_routes, controlled_run, exit, find, #handlearg, #help, interrupted?, #main, #name, option, option_parser_commands, #parse_options, #preinit, restart!, restart_requested?, #run_command, run_mode, #set_run_mode, #setup, #setup_logs, should_not_parse_config, should_parse_config, #should_parse_config?, should_parse_config?, stop!, stop_requested?

Methods included from Util

absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask

Methods included from Util::POSIX

#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid

Constructor Details

#initialize(full_module_name, options = {}) ⇒ Generator

Returns a new instance of Generator.



9
10
11
12
13
14
15
16
# File 'lib/vendor/puppet/module_tool/applications/generator.rb', line 9

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

Instance Method Details

#destinationObject



69
70
71
# File 'lib/vendor/puppet/module_tool/applications/generator.rb', line 69

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

#get_bindingObject



22
23
24
# File 'lib/vendor/puppet/module_tool/applications/generator.rb', line 22

def get_binding
  binding
end

#runObject



26
27
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
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vendor/puppet/module_tool/applications/generator.rb', line 26

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

  # Return an array of Pathname objects representing file paths of files
  # and directories just generated. This return value is used by the
  # module_tool face generate action, and displayed on the console.
  #
  # Example return value:
  #
  #   [
  #     #<Pathname:puppetlabs-apache>,
  #     #<Pathname:puppetlabs-apache/tests>,
  #     #<Pathname:puppetlabs-apache/tests/init.pp>,
  #     #<Pathname:puppetlabs-apache/spec>,
  #     #<Pathname:puppetlabs-apache/spec/spec_helper.rb>,
  #     #<Pathname:puppetlabs-apache/spec/spec.opts>,
  #     #<Pathname:puppetlabs-apache/README>,
  #     #<Pathname:puppetlabs-apache/Modulefile>,
  #     #<Pathname:puppetlabs-apache/metadata.json>,
  #     #<Pathname:puppetlabs-apache/manifests>,
  #     #<Pathname:puppetlabs-apache/manifests/init.pp"
  #   ]
  #
  files_created
end

#skeletonObject



18
19
20
# File 'lib/vendor/puppet/module_tool/applications/generator.rb', line 18

def skeleton
  @skeleton ||= Skeleton.new
end