Class: Y2Packager::Resolvable
- Inherits:
-
Object
- Object
- Y2Packager::Resolvable
- Includes:
- Yast::Logger
- Defined in:
- library/packages/src/lib/y2packager/resolvable.rb
Overview
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)
Class Method Summary collapse
-
.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.
-
.find(params, preload = []) ⇒ Array<Y2Packager::Resolvable>
Find the resolvables which match the input parameters.
-
.none?(params) ⇒ Boolean
Return true when there is no resolvable matching the requested parameters or false otherwise.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Backward compatibility method to access resolvable like hash.
-
#initialize(hash) ⇒ Resolvable
constructor
Constructor, initialize the object from a pkg-bindings resolvable hash.
-
#method_missing(method, *args) ⇒ Object
Dynamically load the missing attributes from libzypp.
-
#respond_to_missing?(method, _private) ⇒ Boolean
defines for dynamic methods also respond_to?.
Constructor Details
#initialize(hash) ⇒ Resolvable
Constructor, initialize the object from a pkg-bindings resolvable hash.
97 98 99 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 97 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.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 121 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 raise "Missing attributes for identifying the resolvable." 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}") 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.
80 81 82 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 80 def self.any?(params) Yast::Pkg.AnyResolvable(params) end |
.find(params, preload = []) ⇒ Array<Y2Packager::Resolvable>
The regular expressions used in the RPM dependency filters (e.g. "provides_regexp", "supplements_regexp") are POSIX extended regular expressions, not Ruby regular expressions!
Find the resolvables which match the input parameters. See Yast::Pkg.Resolvables
62 63 64 65 66 67 68 69 70 71 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 62 def self.find(params, preload = []) attrs = (preload + UNIQUE_ATTRIBUTES + OPTIONAL_ATTRIBUTES).uniq resolvables = Yast::Pkg.Resolvables(params, attrs) # currently nil is returned only when an invalid regular expression # is passed in a RPM dependency filter (like supplements_regexp: "autoyast(") raise ArgumentError, Yast::Pkg.LastError if resolvables.nil? resolvables.map { |r| new(r) } end |
.none?(params) ⇒ Boolean
Return true when there is no resolvable matching the requested parameters or false otherwise.
89 90 91 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 89 def self.none?(params) !any?(params) end |
Instance Method Details
#[](key) ⇒ Object
Backward compatibility method to access resolvable like hash.
102 103 104 105 106 107 108 109 110 111 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 102 def [](key) log.info "Calling [] with #{key}. It is deprecated. Use method name " \ "directly. Called from #{caller(1).first}" public_send(key.to_sym) # key not found, so return nil to be compatible rescue NameError log.warn "attribute #{key} not defined, returning nil." nil end |
#respond_to_missing?(method, _private) ⇒ Boolean
defines for dynamic methods also respond_to?
139 140 141 142 143 144 |
# File 'library/packages/src/lib/y2packager/resolvable.rb', line 139 def respond_to_missing?(method, _private) return true if instance_variable_defined?("@#{method}") return true if UNIQUE_ATTRIBUTES.include?(method.to_sym) false end |