File: modules.rb

package info (click to toggle)
puppet 5.5.10-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 21,116 kB
  • sloc: ruby: 250,669; sh: 1,620; xml: 218; makefile: 151; sql: 103
file content (47 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module PuppetSpec::Modules
  class << self
    def create(name, dir, options = {})
      module_dir = File.join(dir, name)
      FileUtils.mkdir_p(module_dir)

      environment = options[:environment]

      if metadata = options[:metadata]
        metadata[:source]  ||= 'github'
        metadata[:author]  ||= 'puppetlabs'
        metadata[:version] ||= '9.9.9'
        metadata[:license] ||= 'to kill'
        metadata[:dependencies] ||= []

        metadata[:name] = "#{metadata[:author]}/#{name}"

        File.open(File.join(module_dir, 'metadata.json'), 'w') do |f|
          f.write(metadata.to_json)
        end
      end

      if tasks = options[:tasks]
        tasks_dir = File.join(module_dir, 'tasks')
        FileUtils.mkdir_p(tasks_dir)
        tasks.each do |task_files|
          task_files.each do |task_file|
            FileUtils.touch(File.join(tasks_dir, task_file))
          end
        end
      end

      Puppet::Module.new(name, module_dir, environment)
    end

    def generate_files(name, dir, options = {})
      module_dir = File.join(dir, name)
      FileUtils.mkdir_p(module_dir)

      if metadata = options[:metadata]
        File.open(File.join(module_dir, 'metadata.json'), 'w') do |f|
          f.write(metadata.to_json)
        end
      end
    end
  end
end