Class: Xtrn::Directory

Inherits:
Object
  • Object
show all
Defined in:
lib/xtrn/directory.rb

Instance Method Summary collapse

Constructor Details

#initialize(config, executor) ⇒ Directory

Returns a new instance of Directory.



6
7
8
9
# File 'lib/xtrn/directory.rb', line 6

def initialize(config, executor)
  @config = config
  @executor = executor
end

Instance Method Details

#update!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/xtrn/directory.rb', line 11

def update!
  @config.each do |entry|
    username = entry['username'] ? "--username '#{entry['username']}' " : ''
    password = entry['password'] ? "--password '#{entry['password']}' " : ''

    standard_args = "--no-auth-cache" unless entry['cache_credentials']

    x = @executor.exec("svn info #{username}#{password}#{standard_args} #{entry['url']}")
    rev = YAML.load(x)["Last Changed Rev"]
    cmd = if File.directory?(entry['path'])
      'update'
    else
      'checkout'
    end
    @executor.exec("svn #{cmd} #{username}#{password}#{standard_args} -r#{rev} #{entry['url']} #{entry['path']}")
  end

  def updated_gitignore(original_gitignore)
    to_add = @config.map{|i|i['path']}
    
    original_gitignore.each_line do |line|
      line.strip!
      to_add.delete(line)
    end
    return original_gitignore if to_add.empty?
    [*original_gitignore.lines.map(&:"strip!"), *to_add].join("\n")
  end
end

#updated_gitignore(original_gitignore) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/xtrn/directory.rb', line 28

def updated_gitignore(original_gitignore)
  to_add = @config.map{|i|i['path']}
  
  original_gitignore.each_line do |line|
    line.strip!
    to_add.delete(line)
  end
  return original_gitignore if to_add.empty?
  [*original_gitignore.lines.map(&:"strip!"), *to_add].join("\n")
end