Class: AptControl::Commands::Set

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

Instance Method Summary collapse

Constructor Details

#initialize(dependencies) ⇒ Set

Returns a new instance of Set.



4
5
6
# File 'lib/apt_control/commands/set.rb', line 4

def initialize(dependencies)
  @control_file = dependencies.fetch(:control_file)
end

Instance Method Details

#run(distribution_name, package_name, constraint) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/apt_control/commands/set.rb', line 8

def run(distribution_name, package_name, constraint)
  distribution = @control_file[distribution_name] or
    raise ArgumentError, "no such distribution: #{distribution_name}"

  package_rule = distribution[package_name] or
    raise ArgumentError, "no such package: #{package_name}"

  begin
    package_rule.constraint = constraint
  rescue => e
    raise ArgumentError, "could not set constraint: #{e}"
  end

  @control_file.write
end