Class: VMC::App::Routes

Inherits:
Base
  • Object
show all
Defined in:
lib/vmc/cli/app/routes.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

#mapObject



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
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/vmc/cli/app/routes.rb', line 12

def map
  app = input[:app]

  simple = input[:url].sub(/^https?:\/\/(.*)\/?/i, '\1')

  if v2?
    host, domain_name = simple.split(".", 2)

    domain =
      client.current_space.domain_by_name(domain_name, :depth => 0)

    fail "Invalid domain '#{domain_name}'" unless domain

    route = client.routes_by_host(host, :depth => 0).find do |r|
      r.domain == domain
    end

    unless route
      route = client.route

      with_progress("Creating route #{c(simple, :name)}") do
        route.host = host
        route.domain = domain
        route.space = app.space
        route.create!
      end
    end

    with_progress("Binding #{c(simple, :name)} to #{c(app.name, :name)}") do
      app.add_route(route)
    end
  else
    with_progress("Updating #{c(app.name, :name)}") do
      app.urls << simple
      app.update!
    end
  end
end

#unmapObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/vmc/cli/app/routes.rb', line 60

def unmap
  app = input[:app]
  url = input[:url, app.urls]

  simple = url.sub(/^https?:\/\/(.*)\/?/i, '\1')

  if v2?
    host, domain_name = simple.split(".", 2)

    domain =
      client.current_space.domain_by_name(domain_name, :depth => 0)

    fail "Invalid domain '#{domain_name}'" unless domain

    route = app.routes_by_host(host, :depth => 0).find do |r|
      r.domain == domain
    end

    fail "Invalid route '#{simple}'" unless route

    with_progress("Removing route #{c(simple, :name)}") do
      app.remove_route(route)
    end
  else
    with_progress("Updating #{c(app.name, :name)}") do |s|
      unless app.urls.delete(simple)
        s.fail do
          err "URL #{url} is not mapped to this application."
          return
        end
      end

      app.update!
    end
  end
end