Class: AptControl::ControlFile::PackageRule

Inherits:
Object
  • Object
show all
Defined in:
lib/apt_control/control_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, constraint) ⇒ PackageRule

Returns a new instance of PackageRule.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/apt_control/control_file.rb', line 76

def initialize(name, constraint)
  @package_name = name
  version = nil
  constraint.split(" ").tap do |split|
    @restriction, version = if split.size == 1
                               ['=', split.first]
                             else
                               split
                             end
  end

  ['=', '>=', '~>'].include?(@restriction) or
    raise "unrecognised restriction: '#{@restriction}'"

  @version = Version.parse(version)
end

Instance Attribute Details

#package_nameObject (readonly)

name of package rule applies to



68
69
70
# File 'lib/apt_control/control_file.rb', line 68

def package_name
  @package_name
end

#restrictionObject (readonly)

symbol for rule



74
75
76
# File 'lib/apt_control/control_file.rb', line 74

def restriction
  @restriction
end

#versionObject (readonly)

version number for restriction comparison



71
72
73
# File 'lib/apt_control/control_file.rb', line 71

def version
  @version
end

Instance Method Details

#higher_available?(included, available) ⇒ Boolean

will return true if their is a version in available that is higher than included

Returns:

  • (Boolean)


95
96
97
# File 'lib/apt_control/control_file.rb', line 95

def higher_available?(included, available)
  available.find {|a| a > included }
end

#satisfied_by?(included) ⇒ Boolean

will return true if included satisfies this rule

Returns:

  • (Boolean)


100
101
102
103
104
105
106
107
108
109
110
# File 'lib/apt_control/control_file.rb', line 100

def satisfied_by?(included)
  case @restriction
  when '='
    included.satisfies_exactly(version)
  when '>='
    included.satisfies_loosely(version)
  when '~>'
    included.satisfies_pessimisticly(version)
  else raise "this shouldn't have happened"
  end
end

#upgradeable?(included, available) ⇒ Boolean

will return true if a) there is a higher version available than is included b) any of the available packages satisfy this rule

Returns:

  • (Boolean)


114
115
116
117
118
# File 'lib/apt_control/control_file.rb', line 114

def upgradeable?(included, available)
  return false unless higher_available?(included, available)
  higher = available.select {|a| a > included }
  return true if higher.any? {|a| satisfied_by?(a) }
end

#upgradeable_to(available) ⇒ Object

will return the subset of versions from available that satisfy this rule



121
122
123
# File 'lib/apt_control/control_file.rb', line 121

def upgradeable_to(available)
  available.select {|a| satisfied_by?(a) }
end