Class: Ports::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/port_upgrade/port.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(portname) ⇒ Port

Returns a new instance of Port.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/port_upgrade/port.rb', line 5

def initialize(portname)
  tmpp = File.join(RECEIPT_PATH,portname)
  @name = portname
  @versions = []
  if File.exist?(tmpp) and File.readable?(tmpp)
    @rp = tmpp
    Find.find(@rp) do |d|
      next unless File.directory?(d)
      next if d == @rp
      b = File.basename(d)
      md = /([^+]+)((\+\w+)*)/.match(b)
      @versions << md[1] unless md.nil?
    end
  end

  Dir.entries(MACPORTS_DB).each do |d|
    if File.directory?(File.join(MACPORTS_DB,d)) && d != '.' && d != '..'
      testpath = File.join(MACPORTS_DB,d,@name,'Portfile')
      if File.exist?(testpath)
        @portfile_path = testpath
        break
      end
    end
  end
  raise "NoSuchPort: #{@name}" if @portfile_path.nil?
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/port_upgrade/port.rb', line 3

def name
  @name
end

#portfile_pathObject (readonly)

Returns the value of attribute portfile_path.



3
4
5
# File 'lib/port_upgrade/port.rb', line 3

def portfile_path
  @portfile_path
end

#versionsObject (readonly)

Returns the value of attribute versions.



3
4
5
# File 'lib/port_upgrade/port.rb', line 3

def versions
  @versions
end

Instance Method Details

#installed?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/port_upgrade/port.rb', line 32

def installed?
  @rp.nil? ? false : true
end

#outdated?Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
62
# File 'lib/port_upgrade/port.rb', line 53

def outdated?
  result = false
  @versions.each do |v|
    if Ports::Utilities.cmp_vers(v,portfile.version) < 0
      result = true
      break
    end
  end
  result
end

#portfileObject



44
45
46
47
# File 'lib/port_upgrade/port.rb', line 44

def portfile
  return nil if @portfile_path.nil?
  @portfile ||= Ports::Portfile.new(@portfile_path)
end

#receipt_pathObject



40
41
42
# File 'lib/port_upgrade/port.rb', line 40

def receipt_path
  @rp
end

#receipt_path=(path) ⇒ Object



36
37
38
# File 'lib/port_upgrade/port.rb', line 36

def receipt_path=(path)
  @rp = path
end