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.



111
112
113
114
# File 'lib/apt_control/control_file.rb', line 111

def initialize(name, constraint)
  @package_name = name
  self.constraint = constraint
end

Instance Attribute Details

#package_nameObject (readonly)

name of package rule applies to



103
104
105
# File 'lib/apt_control/control_file.rb', line 103

def package_name
  @package_name
end

#restrictionObject (readonly)

symbol for rule



109
110
111
# File 'lib/apt_control/control_file.rb', line 109

def restriction
  @restriction
end

#versionObject (readonly)

version number for restriction comparison



106
107
108
# File 'lib/apt_control/control_file.rb', line 106

def version
  @version
end

Instance Method Details

#constraint=(constraint) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/apt_control/control_file.rb', line 116

def constraint=(constraint)
  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

#higher_available?(included, available) ⇒ Boolean

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

Returns:

  • (Boolean)


134
135
136
# File 'lib/apt_control/control_file.rb', line 134

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

#includeable?(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)


153
154
155
156
157
# File 'lib/apt_control/control_file.rb', line 153

def includeable?(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

#includeable_to(available) ⇒ Object

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



160
161
162
# File 'lib/apt_control/control_file.rb', line 160

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

#restriction_stringObject Also known as: to_s



164
165
166
# File 'lib/apt_control/control_file.rb', line 164

def restriction_string
  "#{@restriction} #{@version}"
end

#satisfied_by?(included) ⇒ Boolean

will return true if included satisfies this rule

Returns:

  • (Boolean)


139
140
141
142
143
144
145
146
147
148
149
# File 'lib/apt_control/control_file.rb', line 139

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