Method: Guard.initialize_template

Defined in:
lib/guard.rb

.initialize_template(guard_name = nil) ⇒ Object

Creates the initial Guardfile template or add a Guard implementation Guardfile template to an existing Guardfile.

Parameters:

  • guard_name (String) (defaults to: nil)

    the name of the Guard to initialize

See Also:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/guard.rb', line 31

def initialize_template(guard_name = nil)
  if !File.exist?('Guardfile')
    ::Guard::UI.info "Writing new Guardfile to #{ Dir.pwd }/Guardfile"
    FileUtils.cp(GUARDFILE_TEMPLATE, 'Guardfile')
  elsif guard_name.nil?
    ::Guard::UI.error "Guardfile already exists at #{ Dir.pwd }/Guardfile"
    exit 1
  end

  if guard_name
    guard_class = ::Guard.get_guard_class(guard_name)
    guard_class.init(guard_name)
  end
end