Class: Y2Packager::Resolvable

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/y2packager/resolvable.rb

Overview

Note:

The returned Resolvables might not be valid anymore after changing the package manager status (installing/removing packages, changing repositories, etc.). After such a change you need to load the resolvables again, avoid storing them for later if possible.

This class represents a libzypp resolvable object (package, pattern, patch, product, source package)

Examples:

All installed packages

Y2Packager::Resolvable.find(kind: :package, status: :installed)

Available (not installed) “yast2” packages

Y2Packager::Resolvable.find(kind: :package, status: :available, name: "yast2")

Lazy loading

res = Y2Packager::Resolvable.find(kind: :package, status: :installed)
# the `summary` attribute is loaded from libzypp when needed
res.each {|r| puts "#{r.name} - {r.summary}"}

Preloading the attributes

# the `summary` attribute is loaded from libzypp already at the initial state
res = Y2Packager::Resolvable.find(kind: :package, status: :installed, [:summary])
# this returns the cached `summary` attribute, this is much more efficient
res.each {|r| puts "#{r.name} - {r.summary}"}

Since:

  • 4.2.6

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Resolvable

Constructor, initialize the object from a pkg-bindings resolvable hash.

Since:

  • 4.2.6


79
80
81
# File 'src/lib/y2packager/resolvable.rb', line 79

def initialize(hash)
  from_hash(hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Dynamically load the missing attributes from libzypp.

Since:

  • 4.2.6


91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'src/lib/y2packager/resolvable.rb', line 91

def method_missing(method, *args)
  if instance_variable_defined?("@#{method}")
    raise ArgumentError, "Method #{method} does not accept arguments" unless args.empty?
    return instance_variable_get("@#{method}")
  end

  # load a missing attribute
  if UNIQUE_ATTRIBUTES.all? { |a| instance_variable_defined?("@#{a}") }
    load_attribute(method)
    super unless instance_variable_defined?("@#{method}")
    raise ArgumentError, "Method #{method} does not accept arguments" unless args.empty?
    instance_variable_get("@#{method}")
  else
    raise "Missing attributes for identifying the resolvable."
  end
end

Class Method Details

.any?(params) ⇒ Boolean

Is there any resolvable matching the requested parameters? This is similar to the .find method, just instead of a resolvable list it returns a simple Boolean.

See Also:

Since:

  • 4.2.6


71
72
73
# File 'src/lib/y2packager/resolvable.rb', line 71

def self.any?(params)
  Yast::Pkg.AnyResolvable(params)
end

.find(params, preload = []) ⇒ Array<Y2Packager::Resolvable>

Find the resolvables which match the input parameters. See Yast::Pkg.Resolvables

See Also:

Since:

  • 4.2.6


59
60
61
62
# File 'src/lib/y2packager/resolvable.rb', line 59

def self.find(params, preload = [])
  attrs = (preload + UNIQUE_ATTRIBUTES).uniq
  Yast::Pkg.Resolvables(params, attrs).map { |r| new(r) }
end