Module: Canals

Extended by:
Canals
Included in:
Canals
Defined in:
lib/canals.rb,
lib/canals/cli.rb,
lib/canals/core.rb,
lib/canals/config.rb,
lib/canals/options.rb,
lib/canals/session.rb,
lib/canals/version.rb,
lib/canals/cli/list.rb,
lib/canals/cli/setup.rb,
lib/canals/repository.rb,
lib/canals/tools/yaml.rb,
lib/canals/cli/helpers.rb,
lib/canals/cli/session.rb,
lib/canals/environment.rb,
lib/canals/tools/assets.rb,
lib/canals/cli/environment.rb,
lib/canals/tools/completion.rb

Overview

a gem for managing ssh tunnel connections

Defined Under Namespace

Modules: Cli, Tools Classes: CanalEnvironmentError, CanalOptions, Config, Environment, Exception, Repository, Session

Constant Summary collapse

CanalOptionError =
Class.new StandardError
VERSION =

Canals gem current version

"0.9.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



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

def logger
  @logger
end

Class Method Details

.create_tunnel(tunnel_opts) ⇒ Object



10
11
12
# File 'lib/canals/core.rb', line 10

def create_tunnel(tunnel_opts)
  Canals.repository.add tunnel_opts
end

.isalive?(tunnel_opts) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
52
53
# File 'lib/canals/core.rb', line 44

def isalive?(tunnel_opts)
  if tunnel_opts.instance_of? String
    if (Canals.repository.has?(tunnel_opts))
      tunnel_opts = Canals.repository.get(tunnel_opts)
    else
      tunnel_opts = Canals.session.get_obj(tunnel_opts)
    end
  end
  !!tunnel_pid(tunnel_opts)
end

.restart(tunnel_opts) ⇒ Object



39
40
41
42
# File 'lib/canals/core.rb', line 39

def restart(tunnel_opts)
  stop(tunnel_opts)
  start(tunnel_opts)
end

.start(tunnel_opts) ⇒ Object

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/canals/core.rb', line 14

def start(tunnel_opts)
  if tunnel_opts.instance_of? String
    tunnel_opts = Canals.repository.get(tunnel_opts)
  end
  exit_code = tunnel_start(tunnel_opts)
  raise Canals::Exception, "could not start tunnel" unless exit_code.success?
  pid = tunnel_pid(tunnel_opts)
  session_data = {name: tunnel_opts.name, pid: pid, socket: socket_file(tunnel_opts)}
  session_data = tunnel_opts.to_hash(:full).merge(session_data) if tunnel_opts.adhoc
  Canals.session.add(session_data)
  pid.to_i
end

.stop(tunnel_opts, remove_from_session: true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/canals/core.rb', line 27

def stop(tunnel_opts, remove_from_session: true)
  if tunnel_opts.instance_of? String
    if (Canals.repository.has?(tunnel_opts))
      tunnel_opts = Canals.repository.get(tunnel_opts)
    else
      tunnel_opts = Canals.session.get_obj(tunnel_opts)
    end
  end
  tunnel_close(tunnel_opts)
  Canals.session.del(tunnel_opts.name) if remove_from_session
end

Instance Method Details

#configObject



16
17
18
19
# File 'lib/canals.rb', line 16

def config
  return @config if defined?(@config)
  @config = Config.new(File.join(Dir.home, '.canals'))
end

#environmentsObject



26
27
28
29
30
# File 'lib/canals.rb', line 26

def environments
  return @repository.environments if defined?(@repository)
  @repository = Repository.new
  @repository.environments
end

#repositoryObject



21
22
23
24
# File 'lib/canals.rb', line 21

def repository
  return @repository if defined?(@repository)
  @repository = Repository.new
end

#sessionObject



32
33
34
35
# File 'lib/canals.rb', line 32

def session
  return @session if defined?(@session)
  @session = Session.new
end