Module: Kickstart

Defined in:
lib/kickstart.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.copy(src, dest) ⇒ Object

Copy a project from src to dest.



44
45
46
47
48
49
50
51
# File 'lib/kickstart.rb', line 44

def copy src,dest
  if File.exists?(File.join(current_dir,dest))
    puts "File aready exists"
  else
    FileUtils.cp_r(File.join(template_dir,src), current_dir)
    rename_project("javascript_template",dest)
  end
end

.current_dirObject



21
22
23
# File 'lib/kickstart.rb', line 21

def current_dir
  Dir.pwd
end

.find_project_template(template_name) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/kickstart.rb', line 53

def find_project_template template_name
  if list_project_templates.include?(template_name)
    File.join(template_dir.to_s, template_name)
  else
    return nil
  end
end

.join_path(path) ⇒ Object



25
26
27
# File 'lib/kickstart.rb', line 25

def join_path(path)
  File.join(template_dir,path)
end

.kickstart(project_name, template_name) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/kickstart.rb', line 61

def kickstart(project_name, template_name)
  if list_project_templates.include?(template_name)
    unless File.exists?(project_name)
      copy(template_name,project_name)
      puts "Created new project #{project_name} from template: #{template_name}"
    end
  else
    puts "Can't find template #{template_name} in #{template_dir}"
  end
end

.list_project_templatesObject

Returns all project templates in the template directory



34
35
36
37
38
39
# File 'lib/kickstart.rb', line 34

def list_project_templates
  fn = ->(path,file){ File.directory? path }
  Dir.entries(template_dir).select { |file| fn.(template_dir,file) }.reject do |folder|
    folder == "." || folder == ".."
  end
end

.rename_project(old_name, new_name) ⇒ Object



29
30
31
# File 'lib/kickstart.rb', line 29

def rename_project(old_name, new_name)
  File.rename("./#{old_name}", "./#{new_name}")
end

.template_dirObject

This needs to be set explicitly as an ENV variable

Returns:

A string representing the path to your template directory

This needs to be set explicitly as an ENV variable e.g export KICKSTART=“/Users/owainlewis/projects/ruby/kickstart/test/sample_projects/”



17
18
19
# File 'lib/kickstart.rb', line 17

def template_dir
  ENV["KICKSTART"]
end