Class: AptControl::ControlFile::Distribution

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

Overview

represents a set of rules mapped to a particular distribution, i.e. squeeze is a distribution

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, rules) ⇒ Distribution

Returns a new instance of Distribution.



177
178
179
180
# File 'lib/apt_control/control_file.rb', line 177

def initialize(name, rules)
  @name = name
  @package_rules = rules
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



182
183
184
# File 'lib/apt_control/control_file.rb', line 182

def name
  @name
end

#package_rulesObject (readonly)

Returns the value of attribute package_rules.



183
184
185
# File 'lib/apt_control/control_file.rb', line 183

def package_rules
  @package_rules
end

Instance Method Details

#[](package_name) ⇒ Object

find a PackageRule by package name



192
193
194
# File 'lib/apt_control/control_file.rb', line 192

def [](package_name)
  package_rules.find {|rule| rule.package_name == package_name }
end

#[]=(package_name, new_constraint) ⇒ Object



196
197
198
199
200
201
202
203
# File 'lib/apt_control/control_file.rb', line 196

def []=(package_name, new_constraint)
  existing_rule = self[package_name]
  if existing_rule
    existing_rule.constraint = new_constraint
  else
    package_rules << PackageRule.new(package_name, new_constraint)
  end
end

#each(&block) ⇒ Object



185
186
187
188
189
# File 'lib/apt_control/control_file.rb', line 185

def each(&block)
  (@package_rules || []).each do |rule|
    yield(rule)
  end
end