Class: VMC::Route::Unmap

Inherits:
Base show all
Defined in:
lib/vmc/cli/route/unmap.rb

Instance Method Summary collapse

Methods inherited from Base

#precondition

Methods inherited from V2CheckCLI

#fail_on_v2, #precondition

Methods inherited from CLI

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

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

#unmapObject



15
16
17
18
19
20
21
22
23
24
25
26
27
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
# File 'lib/vmc/cli/route/unmap.rb', line 15

def unmap
  return invoke :v1_unmap, input.inputs, input.given unless v2?

  if input[:all]
    if input.has?(:app)
      app = target = input[:app]
      return unless !input[:delete] || input[:really, "ALL URLS bound to #{target.name}", :bad]
    else
      target = client
      return unless !input[:delete] || input[:really, "ALL URLS", :bad]
    end

    target.routes.each do |r|
      begin
        invoke :unmap, :delete => input[:delete], :url => r, :really => true, :app => app
      rescue CFoundry::APIError => e
        err "#{e.class}: #{e.message}"
      end
    end

    return
  end

  app = input[:app]
  url = input[:url, app ? app.routes : client.routes]

  if input[:delete]
    with_progress("Deleting route #{c(url.name, :name)}") do
      url.delete!
    end
  elsif app
    with_progress("Unbinding #{c(url.name, :name)} from #{c(app.name, :name)}") do
      app.remove_route(url)
    end
  else
    fail "Missing either --delete or --app."
  end
end

#v1_unmapObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vmc/cli/route/unmap.rb', line 61

def v1_unmap
  app = input[:app]
  url = input[:url, app.urls] unless input[:all]

  with_progress("Updating #{c(app.name, :name)}") do |s|
    if input[:all]
      app.urls = []
    else
      simple = url.sub(/^https?:\/\/(.*)\/?/i, '\1')

      unless app.urls.delete(simple)
        fail "URL #{url} is not mapped to this application."
      end
    end

    app.update!
  end
end