class Canals::CanalOptions
Constants
- BIND_ADDRESS
Attributes
adhoc[R]
env[R]
env_name[R]
local_port[R]
name[R]
remote_host[R]
remote_port[R]
socks[R]
Public Class Methods
new(args)
click to toggle source
# 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
Public Instance Methods
bind_address()
click to toggle source
# 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_options()
click to toggle source
# 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
hostname()
click to toggle source
# File lib/canals/options.rb, line 41 def hostname get_env_var(:hostname) end
pem()
click to toggle source
# File lib/canals/options.rb, line 49 def pem get_env_var(:pem) end
proxy()
click to toggle source
# File lib/canals/options.rb, line 53 def proxy prxy = "" prxy += "-i #{pem} " if pem prxy += "#{user}@#{hostname}" prxy end
to_hash(mode=:basic)
click to toggle source
# 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_s()
click to toggle source
# File lib/canals/options.rb, line 31 def to_s return "CanalOptions<#{@args}>" end
to_yaml()
click to toggle source
# File lib/canals/options.rb, line 60 def to_yaml Canals::Tools::YAML.to_yaml(@args) end
user()
click to toggle source
# File lib/canals/options.rb, line 45 def user get_env_var(:user) end
Private Instance Methods
get_env_var(var)
click to toggle source
# File lib/canals/options.rb, line 95 def get_env_var(var) return @args[var] if @args[var] return @env.send var.to_sym if @env nil end
validate?(args)
click to toggle source
# File lib/canals/options.rb, line 76 def validate?(args) vargs = args.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo} raise CanalOptionError.new("Missing option: \"name\" in canal creation") if vargs[:name].nil? if vargs[:socks] raise CanalOptionError.new("Missing option: \"local_port\" in canal creation") if vargs[:local_port].nil? else raise CanalOptionError.new("Missing option: \"remote_host\" in canal creation") if vargs[:remote_host].nil? raise CanalOptionError.new("Missing option: \"remote_port\" in canal creation") if vargs[:remote_port].nil? end vargs[:remote_port] = vargs[:remote_port].to_i if vargs[:local_port].nil? vargs[:local_port] = vargs[:remote_port] else vargs[:local_port] = vargs[:local_port].to_i end vargs end