Class: Lobstr::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/lobstr/base.rb

Direct Known Subclasses

Deploy

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app.



4
5
6
# File 'lib/lobstr/base.rb', line 4

def app
  @app
end

#branchObject

Returns the value of attribute branch.



4
5
6
# File 'lib/lobstr/base.rb', line 4

def branch
  @branch
end

#configObject

Returns the value of attribute config.



4
5
6
# File 'lib/lobstr/base.rb', line 4

def config
  @config
end

#environmentObject

Returns the value of attribute environment.



4
5
6
# File 'lib/lobstr/base.rb', line 4

def environment
  @environment
end

#sshObject

Returns the value of attribute ssh.



4
5
6
# File 'lib/lobstr/base.rb', line 4

def ssh
  @ssh
end

Instance Method Details

#connect(&block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/lobstr/base.rb', line 18

def connect(&block)
  @ssh = ::Net::SSH.start(@config['ssh_host'], 
                          @config['ssh_user'], 
                          :keys => [@config['ssh_key']],
                          :auth_methods => %w{ publickey })
  instance_eval(&block) if block_given? 
end

#local_task(cmd) ⇒ Object



30
31
32
# File 'lib/lobstr/base.rb', line 30

def local_task(cmd)
  `#{cmd}`
end

#parse_target(target) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/lobstr/base.rb', line 5

def parse_target(target)
  branch,environment = target.split('@', 2)
 
  if environment.nil? # e.g. production
    environment = branch
    branch = 'master'
  end

  branch = "master" if branch.empty? # e.g. @production
  environment = "production" if environment.empty? # e.g. master@
  [branch,environment]
end

#remote_task(cmd) ⇒ Object



26
27
28
# File 'lib/lobstr/base.rb', line 26

def remote_task(cmd)
  @ssh.exec! cmd
end