class CFBundle::Resource::Predicate
@private
Stores the parameters to select the matching resources while enumerating the resources of a bundle.
Attributes
Returns the extension to match or nil
to match any extension. @return [String?]
Returns the name to match or nil
to match any name. @return [String?, Regexp?]
Returns the product to match. @return [String]
Public Class Methods
@param name [String?, Rexgep?] The name to match or nil
to match any
name.
@param extension [String?] The extension to match or nil
to match any
extension.
@param product [String?] The product to match.
# File lib/cfbundle/resource.rb, line 145 def initialize(name, extension, product) @name = name @extension = extension_for(extension) @product = product_for(product) @keys = Set.new end
Public Instance Methods
Returns whether the predicate matches a given resource.
A predicate ensures resource unicity by the caching the filename of previsouly matched resources. Therefore this method always returns when invoked twice with the same resource.
@param resource [Resource] The resource to test. @return [Boolean]
# File lib/cfbundle/resource.rb, line 160 def match?(resource) directory, name, product, extension = PathUtils.split_resource( resource.path, @product ) extension_match?(extension) && name_match?(name) && product_match?(directory, name, product, extension, resource) && uniq?(name, extension) end
Private Instance Methods
# File lib/cfbundle/resource.rb, line 196 def extension_for(extension) return extension if extension.nil? || extension.empty? extension.start_with?('.') ? extension : '.' + extension end
# File lib/cfbundle/resource.rb, line 172 def extension_match?(extension) @extension.nil? || @extension == extension end
# File lib/cfbundle/resource.rb, line 176 def name_match?(name) @name.nil? || @name === name end
# File lib/cfbundle/resource.rb, line 201 def product_for(product) return '' if product.nil? || product.empty? product.start_with?('~') ? product : '~' + product end
# File lib/cfbundle/resource.rb, line 180 def product_match?(directory, name, product, extension, resource) return true if @product == product return false unless product.empty? exact_path = PathUtils.join_resource( directory, name, @product, extension ) !resource.bundle.storage.exist?(exact_path) end
# File lib/cfbundle/resource.rb, line 189 def uniq?(name, extension) key = [name, extension].join return false if @keys.include?(key) @keys << key true end