Class: HotPotato::Generate

Inherits:
Object
  • Object
show all
Defined in:
lib/hot_potato/generate.rb

Instance Method Summary collapse

Constructor Details

#initialize(app_path) ⇒ Generate

Returns a new instance of Generate.



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
# File 'lib/hot_potato/generate.rb', line 7

def initialize(app_path) 
  @app_path = app_path   
  log "Generating application #{@app_path}..."
  mkdir app_path    
  copy_file "Gemfile"
  copy_file "Rakefile"
  mkdir "app"
  mkdir "bin"
  copy_file "admin", 'bin', 0755
  copy_file "app_task", 'bin', 0755
  copy_file "generate", 'bin', 0755
  copy_file "supervisor", 'bin', 0755
  mkdir "config"
  mkdir "config/environments"
  copy_file "development.rb", 'config/environments'
  copy_file "test.rb", 'config/environments'
  copy_file "production.rb", 'config/environments'
  copy_file "boot.rb", 'config'
  copy_file "config.yml", 'config'
  copy_file "routes.rb", 'config'   
  mkdir "docs"
  mkdir "logs"
  mkdir "test"
  mkdir "tmp"
end

Instance Method Details

#copy_file(src, dest = "", perm = 0644) ⇒ Object



43
44
45
46
47
48
# File 'lib/hot_potato/generate.rb', line 43

def copy_file(src, dest = "", perm = 0644)
  dest = "#{dest}/" unless dest == ""
  log "    add     #{@app_path}/#{dest}#{src}"
  FileUtils.cp "#{File.expand_path('..', __FILE__)}/templates/#{src}", "#{@app_path}/#{dest}#{src}"
  File.chmod perm, "#{@app_path}/#{dest}#{src}"
end

#log(message) ⇒ Object



50
51
52
# File 'lib/hot_potato/generate.rb', line 50

def log(message)
  puts "#{message}"
end

#mkdir(path) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/hot_potato/generate.rb', line 33

def mkdir(path)
  dir = path == @app_path ? @app_path : "#{@app_path}/#{path}"
  if Dir.exists?(dir)
    log "     exist  #{dir}"
  else
    Dir.mkdir(dir)
    log "    create  #{dir}"
  end
end