Class: FsTemplate::Project

Inherits:
Object
  • Object
show all
Includes:
FromHash
Defined in:
lib/fs_template/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/fs_template/project.rb', line 4

def path
  @path
end

Instance Method Details

#commands(phase) ⇒ Object



27
28
29
# File 'lib/fs_template/project.rb', line 27

def commands(phase)
  config.commands.select { |x| x[:phase] == phase }.map { |x| x[:command] }
end

#config_bodyObject



6
7
8
9
10
11
12
13
14
# File 'lib/fs_template/project.rb', line 6

def config_body
  if FileTest.exist?("#{path}/.fstemplate")
    File.read("#{path}/.fstemplate")
  elsif FileTest.exist?("#{path}/.overlay")
    File.read("#{path}/.overlay")
  else
    raise "no config"
  end
end

#git_commit(output_path, message, init = false) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/fs_template/project.rb', line 51

def git_commit(output_path,message,init=false)
  if init
    `rm -rf #{output_path}/.git`
    ec "cd #{output_path} && git init && git config user.email [email protected] && git config user.name 'John Smith'", :silent => true
  end
  ec "cd #{output_path} && git add . && git commit -m '#{message}'", :silent => true
end

#overlay_pathsObject



23
24
25
# File 'lib/fs_template/project.rb', line 23

def overlay_paths
  config.overlays + [path]
end

#write_to!(output_path) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fs_template/project.rb', line 60

def write_to!(output_path)
  commands(:before).each do |cmd|
    FsTemplate.ec "cd #{output_path} && #{cmd}", :silent => true
    git_commit output_path, "Ran Command: #{cmd}"
  end

  base_files.write_to! output_path

  git_commit output_path, "Base Files #{config.base}", true
  combined_files.write_to!(output_path)
  git_commit output_path, "Overlay Files #{path}"

  commands(:after).each do |cmd|
    FsTemplate.ec "cd #{output_path} && #{cmd}", :silent => true
    git_commit output_path, "Ran Command: #{cmd}"
  end
end