Class: Capricorn::CLI::ApplicationsGems

Inherits:
Capricorn::CLI show all
Includes:
Helpers
Defined in:
lib/capricorn-client/cli/applications/gems.rb

Constant Summary

Constants included from Helpers

Helpers::DEFAULT_CONFIG

Instance Method Summary collapse

Methods included from Helpers

#application, #application_ids, #application_info, #applications, #client, #cluster, #config, #environment, #halt, #info, #local_config, #machine, #machines, #node, #nodes

Methods inherited from Capricorn::CLI

banner, #help, #method_missing, start

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Capricorn::CLI

Instance Method Details

#add(gem_name) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/capricorn-client/cli/applications/gems.rb', line 30

def add(gem_name)
  gem_name = gem_name.strip

  machine, id = *application
  app         = application_info

  app[10] ||= []

  if app[10].include?(gem_name)
    halt "Gem is already configured"
  end

  app[10].push(gem_name)

  p client.call.applications.update(machine.to_sym, id, app[4], app[10])
end

#listObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/capricorn-client/cli/applications/gems.rb', line 8

def list
  (application_info[9] || []).sort! do |a,b|
    a[1] <=> b[1]
  end

  (application_info[10] || []).sort! do |a,b|
    a <=> b
  end

  puts "Configured gems:"
  (application_info[10] || []).each do |name|
    puts "- #{name}"
  end
  puts

  puts "Used gems:"
  (application_info[9] || []).each do |gem|
    puts "- #{gem[1]} (#{gem[2].flatten.join('.')})"
  end
end

#remove(gem_name) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/capricorn-client/cli/applications/gems.rb', line 48

def remove(gem_name)
  gem_name = gem_name.strip

  machine, id = *application
  app         = application_info

  app[10] ||= []

  unless app[10].include?(gem_name)
    halt "Gem is not configured"
  end

  app[10].delete(gem_name)

  p client.call.applications.update(machine.to_sym, id, app[4], app[10])
end