Class: Autoproj::OSPackageQuery
- Defined in:
- lib/autoproj/os_package_query.rb
Overview
Match class to query OS packages
This class allows to create a query object based on a textual representation, and then match osdeps packages using this query object.
The queries are of the form
FIELD=VALUE:FIELD~VALUE:FIELD=VALUE
The F=V form requires an exact match while F~V allows partial matches. The different matches are combined with AND (i.e. only packages matching all criterias will be returned)
The following fields are allowed:
* name: the osdep name
* real_package: a regexp that matches the name of the underlying package
* package_manager: a regexp that matches the underlying package manager
Defined Under Namespace
Classes: Adapter
Constant Summary collapse
- ALLOWED_FIELDS =
%w[ name real_package package_manager ]
- DEFAULT_FIELDS =
{ }
Constants inherited from QueryBase
QueryBase::EXACT, QueryBase::PARTIAL
Instance Attribute Summary
Attributes inherited from QueryBase
Class Method Summary collapse
-
.parse(str, os_package_resolver) ⇒ Object
Parse a single field in a query (i.e. a FIELDVALUE string).
Instance Method Summary collapse
-
#initialize(fields, value, partial, os_package_resolver) ⇒ OSPackageQuery
constructor
A new instance of OSPackageQuery.
-
#match(pkg) ⇒ Boolean
Checks if a package matches against the query.
Methods inherited from QueryBase
Constructor Details
#initialize(fields, value, partial, os_package_resolver) ⇒ OSPackageQuery
Returns a new instance of OSPackageQuery.
29 30 31 32 |
# File 'lib/autoproj/os_package_query.rb', line 29 def initialize(fields, value, partial, os_package_resolver) super(fields, value, partial) @os_package_resolver = os_package_resolver end |
Class Method Details
.parse(str, os_package_resolver) ⇒ Object
Parse a single field in a query (i.e. a FIELDVALUE string)
87 88 89 90 91 |
# File 'lib/autoproj/os_package_query.rb', line 87 def self.parse(str, os_package_resolver) fields, value, partial = super(str, allowed_fields: ALLOWED_FIELDS) OSPackageQuery.new(fields, value, partial, os_package_resolver) end |
Instance Method Details
#match(pkg) ⇒ Boolean
Checks if a package matches against the query
If the package matches, the returned value can be one of:
- EXACT
-
this is an exact match
- PARTIAL
-
the expected value can be found in the package field. The match is done in a case-insensitive way
If partial? is not set (i.e. if FIELD=VALUE was used), then only EXACT or false can be returned.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/autoproj/os_package_query.rb', line 73 def match(pkg) pkg = Adapter.new(pkg, @os_package_resolver) pkg_value = fields.inject(pkg) do |v, field_name| v.send(field_name) end return EXACT if pkg_value.include?(value) return unless partial? PARTIAL if pkg_value.any? { |v| @value_rx === v } end |