Class: VMC::App::Delete

Inherits:
Base
  • Object
show all
Defined in:
lib/vmc/cli/app/delete.rb

Instance Method Summary collapse

Methods inherited from Base

#app_status, #human_mb, #human_size, #megabytes, #memory_choices, #state_color

Methods inherited from CLI

#check_logged_in, #check_target, #client, client, client=, #client_target, #color_enabled?, #default_action, #ensure_config_dir, #err, #execute, #fail, #force?, #invalidate_client, #log_error, #name_list, #no_v2, #one_of, #precondition, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #set_target, #table, #target_file, #target_info, #targets_info, #tokens_file, #user_colors, #v2?, #verbose?

Methods included from Spacing

#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes

Methods included from Interactive

#ask, #handler, #input_state, #list_choices, #prompt, #show_default

Instance Method Details

#deleteObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vmc/cli/app/delete.rb', line 28

def delete
  apps = client.apps

  if input[:all]
    return unless input[:really, "ALL APPS", :bad]

    to_delete = apps
    others = []
  else
    to_delete = input[:apps]
    others = apps - to_delete
  end

  orphaned = find_orphaned_services(to_delete, others)

  deleted = []
  spaced(to_delete) do |app|
    really = input[:all] || input[:really, app.name, :name]
    next unless really

    deleted << app

    with_progress("Deleting #{c(app.name, :name)}") do
      app.routes.collect(&:delete!) if input[:routes]
      app.delete!
    end
  end

  delete_orphaned_services(orphaned, input[:orphaned])

  to_delete
end

#delete_orphaned_services(instances, orphaned) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/vmc/cli/app/delete.rb', line 75

def delete_orphaned_services(instances, orphaned)
  return if instances.empty?

  line unless quiet? || force?

  instances.select { |i|
    orphaned ||
      ask("Delete orphaned service instance #{c(i.name, :name)}?",
          :default => false)
  }.each do |instance|
    # TODO: splat
    invoke :delete_service, :instance => instance, :really => true
  end
end

#find_orphaned_services(apps, others = []) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/vmc/cli/app/delete.rb', line 61

def find_orphaned_services(apps, others = [])
  orphaned = Set.new

  apps.each do |a|
    a.services.each do |i|
      if others.none? { |x| x.binds?(i) }
        orphaned << i
      end
    end
  end

  orphaned.each(&:invalidate!)
end