Class: Forward::Tunnel

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/forward/tunnel.rb

Constant Summary

Constants included from Common

Common::EMAIL_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#config, #exit_with_error, #exit_with_message, #logged_in?, #logger, #os, #stop_reactor_and_exit, #windows?

Constructor Details

#initialize(attributes = {}) ⇒ Tunnel

Initializes a Tunnel instance for the Client and requests a tunnel from API.

client - The Client instance.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/forward/tunnel.rb', line 36

def initialize(attributes = {})
  logger.debug "[tunnel] initializing with: #{attributes.inspect}"
  @attributes       = attributes
  @id               = attributes[:id]
  @host             = attributes[:vhost]
  @port             = attributes[:hostport]
  @subdomain_prefix = attributes[:subdomain_prefix]
  @username         = attributes[:username]
  @password         = attributes[:password]
  @no_auth          = attributes[:no_auth]
  @static_path      = attributes[:static_path]
  @cname            = attributes[:cname]
  @timeout          = attributes[:timeout]
  @tunneler         = attributes[:tunneler]
  @url              = attributes[:url]
  @requests         = {}
  @open             = false
  @socket           = Socket.new(self)
end

Instance Attribute Details

#cnameObject (readonly)

The CNAME for the Tunnel



10
11
12
# File 'lib/forward/tunnel.rb', line 10

def cname
  @cname
end

#hostObject (readonly)

The host to forward requests to



12
13
14
# File 'lib/forward/tunnel.rb', line 12

def host
  @host
end

#idObject (readonly)

The Tunnel resource ID



6
7
8
# File 'lib/forward/tunnel.rb', line 6

def id
  @id
end

#last_active_atObject

Returns the value of attribute last_active_at.



30
31
32
# File 'lib/forward/tunnel.rb', line 30

def last_active_at
  @last_active_at
end

#no_authObject (readonly)

Returns the value of attribute no_auth.



18
19
20
# File 'lib/forward/tunnel.rb', line 18

def no_auth
  @no_auth
end

#passwordObject (readonly)

Returns the value of attribute password.



17
18
19
# File 'lib/forward/tunnel.rb', line 17

def password
  @password
end

#portObject (readonly)

The port to forward requests to



14
15
16
# File 'lib/forward/tunnel.rb', line 14

def port
  @port
end

#requestsObject (readonly)

Returns the value of attribute requests.



28
29
30
# File 'lib/forward/tunnel.rb', line 28

def requests
  @requests
end

#socketObject (readonly)

Returns the value of attribute socket.



26
27
28
# File 'lib/forward/tunnel.rb', line 26

def socket
  @socket
end

#socket_urlObject (readonly)

Returns the value of attribute socket_url.



27
28
29
# File 'lib/forward/tunnel.rb', line 27

def socket_url
  @socket_url
end

#subdomainObject (readonly)

The domain for the Tunnel



8
9
10
# File 'lib/forward/tunnel.rb', line 8

def subdomain
  @subdomain
end

#timeoutObject (readonly)

The timeout



24
25
26
# File 'lib/forward/tunnel.rb', line 24

def timeout
  @timeout
end

#tunnelerObject (readonly)

The tunneler host



22
23
24
# File 'lib/forward/tunnel.rb', line 22

def tunneler
  @tunneler
end

#urlObject (readonly)

The public hostname/subdomain url for the tunnel



20
21
22
# File 'lib/forward/tunnel.rb', line 20

def url
  @url
end

#usernameObject (readonly)

Authentication for tunnel



16
17
18
# File 'lib/forward/tunnel.rb', line 16

def username
  @username
end

Instance Method Details

#authorityObject



73
74
75
76
77
78
79
80
# File 'lib/forward/tunnel.rb', line 73

def authority
  @authority ||= begin
    _authority = "#{host}"
    _authority << ":#{port}" unless port == 80

    _authority
  end
end

#destroy(&block) ⇒ Object



69
70
71
# File 'lib/forward/tunnel.rb', line 69

def destroy(&block)
  API::Tunnel.destroy(id, &block)
end

#open?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/forward/tunnel.rb', line 65

def open?
  @open
end

#ready!Object



56
57
58
59
60
61
62
63
# File 'lib/forward/tunnel.rb', line 56

def ready!
  logger.debug '[tunnel] opened successfully'
  @open = true

  copy_url_to_clipboard
  open_url_in_browser
  display_ready_message
end

#track_activity!Object



82
83
84
# File 'lib/forward/tunnel.rb', line 82

def track_activity!
  self.last_active_at = Time.now.to_i
end