Class: CFBundle::Resource::Predicate

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name, extension, product) ⇒ Predicate

Returns a new instance of Predicate.

Parameters:

  • name (String?, Rexgep?)

    The name to match or nil to match any name.

  • extension (String?)

    The extension to match or nil to match any extension.

  • product (String?)

    The product to match.



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

#extensionString? (readonly)

Returns the extension to match or nil to match any extension.

Returns:

  • (String?)


134
135
136
# File 'lib/cfbundle/resource.rb', line 134

def extension
  @extension
end

#nameString?, Regexp? (readonly)

Returns the name to match or nil to match any name.

Returns:

  • (String?, Regexp?)


130
131
132
# File 'lib/cfbundle/resource.rb', line 130

def name
  @name
end

#productString (readonly)

Returns the product to match.

Returns:

  • (String)


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.

Parameters:

  • resource (Resource)

    The resource to test.

Returns:

  • (Boolean)


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