class CFBundle::Resource
A {Resource} is an abstraction of file contained within a {Bundle}.
Attributes
Returns the resource's enclosing bundle. @return [Bundle]
Returns the path to the resource within the bundle. @return [String]
Public Class Methods
Enumerates the resources in a bundle that match the specified parameters.
@param bundle [Bundle] The bundle that contains the resources. @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 localization [String?, Symbol?] A language identifier to restrict
the search to a specific localization.
@param preferred_languages [Array] An array of strings (or symbols)
corresponding to a user's preferred languages.
@param product [String?] The product to match or nil
to match any
product.
@yieldparam resource [Resource] @return [nil] When a block is given. @return [Enumerator] When no block is given.
# File lib/cfbundle/resource.rb, line 50 def self.foreach(bundle, name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil, &block) enumerator = ::Enumerator.new do |y| enumerator = Enumerator.new(bundle, subdirectory, localization, preferred_languages) predicate = Predicate.new(name, extension, product) loop do resource = enumerator.next y << resource if predicate.match?(resource) end end enumerator.each(&block) end
@param bundle [Bundle] The resource's enclosing bundle. @param path [String] The path of the resource within the bundle.
# File lib/cfbundle/resource.rb, line 16 def initialize(bundle, path) @bundle = bundle @path = path end
Public Instance Methods
Opens the resource for reading.
With no associated block, the method returns an IO. If the optional block is given, it will be passed the opened file and the file will automatically be closed when the block terminates. @yieldparam file [IO] The opened file. It is automatically closed when the
block terminates.
@return [Object] The return value to the block when a block is given. @return [IO] The opened file. When no block is given.
# File lib/cfbundle/resource.rb, line 30 def open(&block) bundle.storage.open(path, &block) end