Class: Bits::PackageProxy
- Inherits:
-
Object
- Object
- Bits::PackageProxy
- 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
-
#atom ⇒ Object
Returns the value of attribute atom.
-
#criteria ⇒ Object
Returns the value of attribute criteria.
-
#ppps ⇒ Object
Returns the value of attribute ppps.
Instance Method Summary collapse
- #dependencies ⇒ Object
-
#initialize(atom, ppps, criteria) ⇒ PackageProxy
constructor
A new instance of PackageProxy.
- #installed ⇒ Object
-
#installed? ⇒ Boolean
Determines if the specified package is installed or not.
-
#matches_criteria?(params) ⇒ Boolean
Check if the following set of parameters matches the specified criteria.
- #matching_ppps ⇒ Object
- #providers ⇒ Object
- #providers_s ⇒ Object
-
#remove ⇒ Object
Remove the specified package.
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
#atom ⇒ Object
Returns the value of attribute atom.
8 9 10 |
# File 'lib/bits/package_proxy.rb', line 8 def atom @atom end |
#criteria ⇒ Object
Returns the value of attribute criteria.
8 9 10 |
# File 'lib/bits/package_proxy.rb', line 8 def criteria @criteria end |
#ppps ⇒ Object
Returns the value of attribute ppps.
8 9 10 |
# File 'lib/bits/package_proxy.rb', line 8 def ppps @ppps end |
Instance Method Details
#dependencies ⇒ Object
21 22 23 |
# File 'lib/bits/package_proxy.rb', line 21 def dependencies ppps.collect{|ppp| ppp.bit.dependencies}.flatten end |
#installed ⇒ Object
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.
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.
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_ppps ⇒ Object
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 |
#providers ⇒ Object
52 53 54 55 56 |
# File 'lib/bits/package_proxy.rb', line 52 def providers ppps.map do |ppp| ppp.provider end end |
#providers_s ⇒ Object
58 59 60 |
# File 'lib/bits/package_proxy.rb', line 58 def providers_s providers.map(&:provider_id).join ', ' end |
#remove ⇒ Object
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 |