class Autoproj::QueryBase
Base implementation for the query classes {SourcePackageQuery} and {OSPackageQuery}
Constants
- EXACT
Match priorities
- PARTIAL
Attributes
The call chain to be matched (i.e. autobuild.name becomes
- ‘autobuild’, ‘name’
The expected value
Public Class Methods
Get a query that matches anything
@return [All]
# File lib/autoproj/query_base.rb, line 31 def self.all All.new end
# File lib/autoproj/query_base.rb, line 35 def initialize(fields, value, partial) @fields = fields @value = value @value_rx = Regexp.new(Regexp.quote(value), true) @partial = partial end
@api private
Parse a single field in a query (i.e. a FIELDVALUE string)
This is NOT meant to be used directly. Subclasses are supposed to redefine .parse to create the relevant match object.
# File lib/autoproj/query_base.rb, line 66 def self.parse(str, allowed_fields: [], default_fields: Hash.new) if (parsed = /[=~]/.match(str)) field = parsed.pre_match value = parsed.post_match partial = (parsed[0] == "~") else raise ArgumentError, "invalid query string '#{str}', expected FIELD and VALUE separated by either = or ~" end field = default_fields[field] || field # Validate the query key unless allowed_fields.include?(field) raise ArgumentError, "'#{field}' is not a known query key" end fields = field.split(".") [fields, value, partial] end
Parse a complete query
# File lib/autoproj/query_base.rb, line 87 def self.parse_query(query, *args) query = query.split(":") query = query.map do |str| parse(str, *args) end if query.size == 1 query.first else And.new(query) end end
Public Instance Methods
Checks if a package matches against the query
@param [String] pkg the osdep package name @return [Boolean] true if it does, false otherwise
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.
# File lib/autoproj/query_base.rb, line 56 def match(pkg) raise NotImplementedError end