Class: Sanctuary::Generator

Inherits:
Thor::Group
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/sanctuary/generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



11
12
13
# File 'lib/sanctuary/generator.rb', line 11

def self.source_root
  Sanctuary::HOME_DIR
end

Instance Method Details

#create_lib_fileObject



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
# File 'lib/sanctuary/generator.rb', line 15

def create_lib_file
  if type == 'recipe'
    File.open(Sanctuary::HOME_DIR.gsub("templates", "recipes/") + template) do |file|
      file.each do |line|
        copy_file "#{line.gsub("||", "/").chomp}", "#{line.split("||")[1..-1].join("/").chomp}"
      end
    end
    if Dir.entries(".").include?('sanctuary-post-recipe-copy-hook.sh')
      system "sh ./sanctuary-post-recipe-copy-hook.sh"
    end
  elsif type == 'script'
    if name.nil?
      system "sh #{Sanctuary::HOME_DIR.gsub("templates", "scripts/")}#{template}"
    else
      system "sh #{Sanctuary::HOME_DIR.gsub("templates", "scripts/")}#{template} #{name}"
    end
  else
    if name.empty?
      # only copy the file and not the directory the file resides in
      copy_file "#{template}", "#{template.split("/").last}"
    else
      copy_file "#{template}", "#{name + "." + template.split("/").last.split(".").last}"
      gsub_file "#{name + "." + template.split("/").last.split(".").last}", "#name", name
    end
  end
end