Class: CFBundle::Resource::Predicate
- Inherits:
-
Object
- Object
- CFBundle::Resource::Predicate
- Defined in:
- lib/cfbundle/resource.rb
Overview
Stores the parameters to select the matching resources while enumerating the resources of a bundle.
Instance Attribute Summary collapse
-
#extension ⇒ String?
readonly
Returns the extension to match or
nil
to match any extension. -
#name ⇒ String?, Regexp?
readonly
Returns the name to match or
nil
to match any name. -
#product ⇒ String
readonly
Returns the product to match.
Instance Method Summary collapse
-
#initialize(name, extension, product) ⇒ Predicate
constructor
A new instance of Predicate.
-
#match?(resource) ⇒ Boolean
Returns whether the predicate matches a given resource.
Constructor Details
#initialize(name, extension, product) ⇒ Predicate
Returns a new instance of Predicate.
145 146 147 148 149 150 |
# 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 |
Instance Attribute Details
#extension ⇒ String? (readonly)
Returns the extension to match or nil
to match any extension.
134 135 136 |
# File 'lib/cfbundle/resource.rb', line 134 def extension @extension end |
#name ⇒ String?, Regexp? (readonly)
Returns the name to match or nil
to match any name.
130 131 132 |
# File 'lib/cfbundle/resource.rb', line 130 def name @name end |
#product ⇒ String (readonly)
Returns the product to match.
138 139 140 |
# File 'lib/cfbundle/resource.rb', line 138 def product @product end |
Instance Method Details
#match?(resource) ⇒ Boolean
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.
160 161 162 163 164 165 166 167 168 |
# 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 |