Class: Bits::PackageProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/bits/package_proxy.rb

Overview

Data class used to keep track of all found ppps (package, provider, params) for a specific bit and the supplied criteria.

This allows for eager loading and lazy lookup of if a specific atom can be considered as ‘installed’ or not.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atom, ppps, criteria) ⇒ PackageProxy

Returns a new instance of PackageProxy.



10
11
12
13
14
# File 'lib/bits/package_proxy.rb', line 10

def initialize(atom, ppps, criteria)
  @atom = atom
  @ppps = ppps
  @criteria = criteria
end

Instance Attribute Details

#atomObject

Returns the value of attribute atom.



8
9
10
# File 'lib/bits/package_proxy.rb', line 8

def atom
  @atom
end

#criteriaObject

Returns the value of attribute criteria.



8
9
10
# File 'lib/bits/package_proxy.rb', line 8

def criteria
  @criteria
end

#pppsObject

Returns the value of attribute ppps.



8
9
10
# File 'lib/bits/package_proxy.rb', line 8

def ppps
  @ppps
end

Instance Method Details

#dependenciesObject



21
22
23
# File 'lib/bits/package_proxy.rb', line 21

def dependencies
  ppps.collect{|ppp| ppp.bit.dependencies}.flatten
end

#installedObject



46
47
48
49
50
# File 'lib/bits/package_proxy.rb', line 46

def installed
  ppps.select do |ppp|
    not ppp.package.installed.nil?
  end
end

#installed?Boolean

Determines if the specified package is installed or not.

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/bits/package_proxy.rb', line 40

def installed?
  ppps.any? do |ppp|
    not ppp.package.installed.nil?
  end
end

#matches_criteria?(params) ⇒ Boolean

Check if the following set of parameters matches the specified criteria.

Returns:

  • (Boolean)


17
18
19
# File 'lib/bits/package_proxy.rb', line 17

def matches_criteria?(params)
  criteria.all?{|key, value| value.nil? or params[key] == value}
end

#matching_pppsObject



25
26
27
28
29
# File 'lib/bits/package_proxy.rb', line 25

def matching_ppps
  ppps.select do |ppp|
    matches_criteria? ppp.parameters
  end
end

#providersObject



52
53
54
55
56
# File 'lib/bits/package_proxy.rb', line 52

def providers
  ppps.map do |ppp|
    ppp.provider
  end
end

#providers_sObject



58
59
60
# File 'lib/bits/package_proxy.rb', line 58

def providers_s
  providers.map(&:provider_id).join ', '
end

#removeObject

Remove the specified package. The package will be removed from all matching PPPs.



33
34
35
36
37
# File 'lib/bits/package_proxy.rb', line 33

def remove
  ppps.each do |ppp|
    ppp.provider.remove ppp.package
  end
end