Class: CFBundle::Resource
- Inherits:
-
Object
- Object
- CFBundle::Resource
- Defined in:
- lib/cfbundle/resource.rb
Overview
Defined Under Namespace
Classes: Enumerator, Predicate
Instance Attribute Summary collapse
-
#bundle ⇒ Bundle
readonly
Returns the resource’s enclosing bundle.
-
#path ⇒ String
readonly
Returns the path to the resource within the bundle.
Class Method Summary collapse
-
.foreach(bundle, name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) {|resource| ... } ⇒ nil, Enumerator
Enumerates the resources in a bundle that match the specified parameters.
Instance Method Summary collapse
-
#initialize(bundle, path) ⇒ Resource
constructor
A new instance of Resource.
-
#open {|file| ... } ⇒ Object, IO
Opens the resource for reading.
Constructor Details
#initialize(bundle, path) ⇒ Resource
Returns a new instance of Resource.
16 17 18 19 |
# File 'lib/cfbundle/resource.rb', line 16 def initialize(bundle, path) @bundle = bundle @path = path end |
Instance Attribute Details
#bundle ⇒ Bundle (readonly)
Returns the resource’s enclosing bundle.
8 9 10 |
# File 'lib/cfbundle/resource.rb', line 8 def bundle @bundle end |
#path ⇒ String (readonly)
Returns the path to the resource within the bundle.
12 13 14 |
# File 'lib/cfbundle/resource.rb', line 12 def path @path end |
Class Method Details
.foreach(bundle, name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) {|resource| ... } ⇒ nil, Enumerator
Enumerates the resources in a bundle that match the specified parameters.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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 |
Instance Method Details
#open {|file| ... } ⇒ Object, IO
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.
30 31 32 |
# File 'lib/cfbundle/resource.rb', line 30 def open(&block) bundle.storage.open(path, &block) end |