Module: Capo::Recipes

Defined in:
lib/capo/recipes.rb

Class Method Summary collapse

Class Method Details

.add(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/capo/recipes.rb', line 12

def add name
  recipe = recipes.select{|r| r[:name] == name}.first
  raise "Recipe '#{name}' not found" unless recipe

  if (dependencies = recipe[:dependencies]).any?
    puts "[#{name}] Installing dependencies first:"
    dependencies.each do |dependency|
      puts "[#{dependency}] Installing depdendency"
      add dependency
    end
  end

  app_recipe_path = File.join app_deploy_path, "#{name}.rb"

  Dir.mkdir(app_deploy_path) unless Dir.exists?(app_deploy_path)

  puts "[#{name}] Copying recipe to #{app_recipe_path}"
  FileUtils.copy File.join(Capo.repository_path, 'recipes', name, "#{name}.rb"), app_recipe_path

  puts "[#{name}] Adding line to Capfile"
  capfile = File.join Capo.app_path, 'Capfile'
  File.open(capfile, 'a+'){|f| f.puts "load 'config/deploy/#{name}'"}

  puts "[#{name}] Recipe added"
end

.addedObject



38
39
40
41
42
43
# File 'lib/capo/recipes.rb', line 38

def added
  puts "Installed recipes:"
  Dir[File.join(app_deploy_path, '*')].each do |recipe|
    puts "  * #{recipe.match(/config\/deploy\/(\w+).rb$/)[1]}"
  end
end

.listObject



4
5
6
7
8
9
10
# File 'lib/capo/recipes.rb', line 4

def list
  longest_name_size = recipes.sort_by{|recipe| recipe[:name].size}.last[:name].size
  recipes.each do |recipe|
    name = recipe[:name]
    puts "#{name}#{' ' * (longest_name_size - name.size)}    #{recipe[:description]}"
  end
end