Class: RemoteTerminal::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/remote-terminal/project.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ Project

Returns a new instance of Project.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/remote-terminal/project.rb', line 7

def initialize(dir)
  tmp = []
  dir.split('/').each do |d|
    if d == '..'
      tmp = tmp[0..-2]
    else
      tmp << d
    end
  end
  @dir = tmp.join('/')
  load_config
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



3
4
5
# File 'lib/remote-terminal/project.rb', line 3

def address
  @address
end

#remote_directoryObject (readonly)

Returns the value of attribute remote_directory.



5
6
7
# File 'lib/remote-terminal/project.rb', line 5

def remote_directory
  @remote_directory
end

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'lib/remote-terminal/project.rb', line 4

def user
  @user
end

Class Method Details

.find(dir) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/remote-terminal/project.rb', line 27

def Project.find(dir)
  if File.exist?(File.join(dir, '.remote-terminal.yml'))
    return Project.new(dir)
  else
    return Project.find(File.join(dir, '..'))
  end
end

Instance Method Details

#load_configObject



20
21
22
23
24
25
# File 'lib/remote-terminal/project.rb', line 20

def load_config
  config = YAML::load(File.open(File.join(@dir, '.remote-terminal.yml')))
  @address = config['address']
  @user = config['user']
  @remote_directory = config['remote_directory']
end

#path_from(dir) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/remote-terminal/project.rb', line 35

def path_from(dir)
  path = ''
  d = dir.gsub(@dir, '').split('/').keep_if {|d| d != ''}
  if d == []
    path = './'
  else
    d.each do |x|
      path += '../'
    end
  end
  return path[0..-2]
end

#path_to(dir) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/remote-terminal/project.rb', line 48

def path_to(dir)
  d = dir.gsub(@dir, '').split('/').keep_if {|d| d != ''}
  if d == []
    return ''
  else
    return "#{d.join('/')}/"
  end
end