Class: Yast2::ArchFilter
- Inherits:
-
Object
- Object
- Yast2::ArchFilter
- Defined in:
- library/general/src/lib/yast2/arch_filter.rb
Overview
Represents filtering based on hardware architecture like x86_64 or ppc64. Original code lived in Y2Storage::SubvolSpecification
Defined Under Namespace
Classes: Invalid
Instance Attribute Summary collapse
-
#specifications ⇒ Array<Hash>
readonly
List of specifications where each entry is hash with key
:method
and:negate
, where method is Yast::Arch method and negate specify if method have to return false.
Class Method Summary collapse
-
.from_string(value) ⇒ Object
Parses architecture filter specification from a string.
Instance Method Summary collapse
-
#initialize(specs) ⇒ ArchFilter
constructor
creates new architecture filter from passed list of individual specifications.
-
#match? ⇒ Boolean
checks if filter match current hardware.
Constructor Details
#initialize(specs) ⇒ ArchFilter
creates new architecture filter from passed list of individual specifications
46 47 48 49 50 51 52 53 54 55 56 |
# File 'library/general/src/lib/yast2/arch_filter.rb', line 46 def initialize(specs) @specifications = [] specs.each do |spec| method = spec.downcase negate = spec.start_with?("!") method = spec[1..-1] if negate raise Invalid, spec unless valid_method?(method) @specifications << { method: method.to_sym, negate: negate } end end |
Instance Attribute Details
#specifications ⇒ Array<Hash> (readonly)
Returns list of specifications where each entry is hash with key :method
and
:negate
, where method is Yast::Arch method and negate specify if
method have to return false. There is one specific method :all
that is not in Yast::Arch,
but can be used to always return true.
41 42 43 |
# File 'library/general/src/lib/yast2/arch_filter.rb', line 41 def specifications @specifications end |
Class Method Details
.from_string(value) ⇒ Object
Parses architecture filter specification from a string.
Supported values are methods from Arch with possible !
in front of it.
When a !
is used it is called a negative method and without it is a positive one.
A list of methods is separated with commas ,
.
To match,
at least one positive specified method has to return true and
all negative methods have to return false.
If there are no positive methods then only negatives are evaluated.
Whitespaces are allowed. Only !
and method has to be without space.
Also it is case insensitive, so acronyms can be in upper case.
82 83 84 |
# File 'library/general/src/lib/yast2/arch_filter.rb', line 82 def self.from_string(value) new(value.split(",").map(&:strip)) end |
Instance Method Details
#match? ⇒ Boolean
checks if filter match current hardware
88 89 90 91 92 93 94 95 96 |
# File 'library/general/src/lib/yast2/arch_filter.rb', line 88 def match? negative, positive = @specifications.partition { |s| s[:negate] } return false if negative.any? { |s| invoke_method(s[:method]) } # handle case when there is only negative conditions return true if positive.empty? positive.any? { |s| invoke_method(s[:method]) } end |