Class: Canals::CanalOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/canals/options.rb

Constant Summary collapse

BIND_ADDRESS =
"127.0.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CanalOptions

Returns a new instance of CanalOptions.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/canals/options.rb', line 18

def initialize(args)
  @original_args = validate?(args)
  @args = Marshal.load(Marshal.dump(@original_args))
  @name = @args[:name]
  @remote_host = @args[:remote_host]
  @remote_port = @args[:remote_port]
  @local_port = @args[:local_port]
  @adhoc = @args[:adhoc] || false
  @socks = @args[:socks] || false
  @env_name = @args[:env]
  @env = Canals.repository.environment(@env_name)
end

Instance Attribute Details

#adhocObject (readonly)

Returns the value of attribute adhoc.



8
9
10
# File 'lib/canals/options.rb', line 8

def adhoc
  @adhoc
end

#envObject (readonly)

Returns the value of attribute env.



8
9
10
# File 'lib/canals/options.rb', line 8

def env
  @env
end

#env_nameObject (readonly)

Returns the value of attribute env_name.



8
9
10
# File 'lib/canals/options.rb', line 8

def env_name
  @env_name
end

#local_portObject (readonly)

Returns the value of attribute local_port.



8
9
10
# File 'lib/canals/options.rb', line 8

def local_port
  @local_port
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/canals/options.rb', line 8

def name
  @name
end

#remote_hostObject (readonly)

Returns the value of attribute remote_host.



8
9
10
# File 'lib/canals/options.rb', line 8

def remote_host
  @remote_host
end

#remote_portObject (readonly)

Returns the value of attribute remote_port.



8
9
10
# File 'lib/canals/options.rb', line 8

def remote_port
  @remote_port
end

#socksObject (readonly)

Returns the value of attribute socks.



8
9
10
# File 'lib/canals/options.rb', line 8

def socks
  @socks
end

Instance Method Details

#bind_addressObject



35
36
37
38
39
# File 'lib/canals/options.rb', line 35

def bind_address
  return @args[:bind_address] if @args[:bind_address]
  return Canals.config[:bind_address] if Canals.config[:bind_address]
  return BIND_ADDRESS
end

#exploded_optionsObject



70
71
72
# File 'lib/canals/options.rb', line 70

def exploded_options
  {bind_address: bind_address, hostname: hostname, user: user, pem: pem, proxy: proxy, adhoc: adhoc, socks: socks}
end

#hostnameObject



41
42
43
# File 'lib/canals/options.rb', line 41

def hostname
  get_env_var(:hostname)
end

#pemObject



49
50
51
# File 'lib/canals/options.rb', line 49

def pem
  get_env_var(:pem)
end

#proxyObject



53
54
55
56
57
58
# File 'lib/canals/options.rb', line 53

def proxy
  prxy = ""
  prxy += "-i #{pem} " if pem
  prxy += "#{user}@#{hostname}"
  prxy
end

#to_hash(mode = :basic) ⇒ Object



64
65
66
67
68
# File 'lib/canals/options.rb', line 64

def to_hash(mode=:basic)
  args_copy = Marshal.load(Marshal.dump(@args))
  args_copy.merge! exploded_options if mode == :full
  args_copy
end

#to_sObject



31
32
33
# File 'lib/canals/options.rb', line 31

def to_s
  return "CanalOptions<#{@args}>"
end

#to_yamlObject



60
61
62
# File 'lib/canals/options.rb', line 60

def to_yaml
  Canals::Tools::YAML.to_yaml(@args)
end

#userObject



45
46
47
# File 'lib/canals/options.rb', line 45

def user
  get_env_var(:user)
end