Class: External

Inherits:
Object
  • Object
show all
Includes:
Sys::Client
Defined in:
lib/sub/external.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sys::Client

#run, #say, #svn, #sys, #verbosity, #verbosity=

Constructor Details

#initialize(parent, name, url, revision = nil) ⇒ External

Returns a new instance of External.



24
25
26
27
28
29
# File 'lib/sub/external.rb', line 24

def initialize(parent, name, url, revision = nil)
  @name = name
  @revision = revision
  @url = url
  @path = "#{parent}/#{@name}"
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/sub/external.rb', line 13

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



13
14
15
# File 'lib/sub/external.rb', line 13

def path
  @path
end

#revisionObject (readonly)

Returns the value of attribute revision.



13
14
15
# File 'lib/sub/external.rb', line 13

def revision
  @revision
end

#urlObject (readonly)

Returns the value of attribute url.



13
14
15
# File 'lib/sub/external.rb', line 13

def url
  @url
end

Class Method Details

.externals_of(parent, prop = `svn propget svn:externals #{parent}`) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/sub/external.rb', line 4

def self.externals_of(parent, prop = `svn propget svn:externals #{parent}`)
  exts = []
  prop.split("\n").each do |prop_line|
    next if prop_line.strip.empty?
    exts << External.from_property_line(parent, prop_line)
  end
  exts
end

.from_property_line(parent, property_line) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/sub/external.rb', line 15

def self.from_property_line(parent, property_line)
  match =  /^(\S+)\s+(-r\s*\d*\s+)?(\S+)\s*$/.match(property_line)
  name = match[1]
  revision = match[2] ? match[2].gsub(/\D/,'').to_i : nil
  url = match[3]
  raise "no url found for '#{property_line}'" if url.nil?
  new(parent, name, url, revision)
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
# File 'lib/sub/external.rb', line 31

def ==(other)
  (path == other.path and url == other.url)
end

#checkoutObject



59
60
61
62
63
# File 'lib/sub/external.rb', line 59

def checkout
  say "Checking out external #{path}"
  rev = revision.nil? ? '' : "-r#{revision}"
  svn("co #{rev} #{url} #{path}")
end

#revision_actualObject



41
42
43
44
# File 'lib/sub/external.rb', line 41

def revision_actual
  info = `svn info #{@path}`
  info.grep(/^Revision:/).first.gsub(/Revision: /, '').to_i
end

#should_update?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/sub/external.rb', line 46

def should_update?
  revision == nil || revision_actual != revision
end

#to_sObject



35
36
37
38
39
# File 'lib/sub/external.rb', line 35

def to_s
  "#{name} " + 
  (revision ? "-r #{revision} " : "") + 
  url
end

#updateObject

todo: test? (indirectly tested via root.rb)



51
52
53
54
55
56
57
# File 'lib/sub/external.rb', line 51

def update
  raise "path is nil" if path.nil?
  say "Updating external #{path}"
  run("svn cleanup #{path}")
  rev = revision.nil? ? '' : "-r#{revision}"
  svn("up #{rev} #{path}", true)
end