Class: CFBundle::Bundle
- Inherits:
-
Object
- Object
- CFBundle::Bundle
- Defined in:
- lib/cfbundle/bundle.rb
Overview
A Bundle is an abstraction of a bundle accessible by the program.
Instance Attribute Summary collapse
-
#storage ⇒ Storage::Base
readonly
The abstract storage used by the bundle.
Class Method Summary collapse
-
.open(file) {|bundle| ... } ⇒ Object, Bundle
Opens a bundle.
Instance Method Summary collapse
-
#build_version ⇒ String?
Returns the bundle’s build version number.
-
#close ⇒ void
Closes the bundle and its underlying storage.
-
#development_localization ⇒ String?
Returns the name of the development language of the bundle.
-
#display_name ⇒ String?
Returns the user-visible name of the bundle.
-
#executable_name ⇒ String?
Returns the name of the bundle’s executable file.
-
#executable_path ⇒ String?
Returns the path of the bundle’s executable file.
-
#find_resource(name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) ⇒ Resource?
Returns the first Resource object that matches the specified parameters.
-
#find_resources(name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) ⇒ Array
Returns all the Resource objects that matches the specified parameters.
-
#identifier ⇒ String?
Returns the bundle identifier from the bundle’s information property list.
-
#info ⇒ Hash
Returns the bundle’s information property list hash.
-
#initialize(file) ⇒ Bundle
constructor
Opens the bundle and returns a new Bundle object.
-
#localizations ⇒ Array
Returns a list of all the localizations contained in the bundle.
-
#name ⇒ String?
Returns the short name of the bundle.
-
#package_type ⇒ String?
Returns the bundle’s OS Type code.
-
#preferred_localizations(preferred_languages) ⇒ Array
Returns an ordered list of preferred localizations contained in the bundle.
-
#release_version ⇒ String?
Returns the bundle’s release version number.
-
#resources_directory ⇒ String
Returns the path of the bundle’s subdirectory that contains its resources.
Constructor Details
#initialize(file) ⇒ Bundle
Opens the bundle and returns a new Bundle object.
A new #storage is automatically created from the file
parameter:
-
If the file is a path to a bundle directory, a new Storage::FileSystem is created that references the bundle at the path.
-
If the file is an
IO
or a path to a ZIP archive, a new Storage::Zip is created that references the bundle within the archive. Therubyzip
gem must be loaded and the archive is expected to contain a single bundle at its root (or inside aPayload
directory for.ipa
archives). -
If the file is a Storage::Base, it is used as the bundle’s storage.
You should send #close
when the bundle is no longer needed.
Note that storages created from an exisiting IO
do not automatically close the file when the bundle is closed.
53 54 55 |
# File 'lib/cfbundle/bundle.rb', line 53 def initialize(file) @storage = StorageDetection.open(file) end |
Instance Attribute Details
#storage ⇒ Storage::Base (readonly)
The abstract storage used by the bundle.
The storage implements the methods that are used by Bundle to read the bundle from the underlying storage (ZIP archive or file system).
71 72 73 |
# File 'lib/cfbundle/bundle.rb', line 71 def storage @storage end |
Class Method Details
.open(file) {|bundle| ... } ⇒ Object, Bundle
24 25 26 27 28 29 30 31 32 |
# File 'lib/cfbundle/bundle.rb', line 24 def self.open(file) bundle = new(file) return bundle unless block_given? begin yield bundle ensure bundle.close end end |
Instance Method Details
#build_version ⇒ String?
Returns the bundle’s build version number.
89 90 91 |
# File 'lib/cfbundle/bundle.rb', line 89 def build_version info_string(CFBundle::INFO_KEY_BUNDLE_VERSION) end |
#close ⇒ void
This method returns an undefined value.
Closes the bundle and its underlying storage.
59 60 61 |
# File 'lib/cfbundle/bundle.rb', line 59 def close @storage.close end |
#development_localization ⇒ String?
Returns the name of the development language of the bundle.
129 130 131 |
# File 'lib/cfbundle/bundle.rb', line 129 def development_localization info_string(CFBundle::INFO_KEY_BUNDLE_DEVELOPMENT_REGION) end |
#display_name ⇒ String?
Returns the user-visible name of the bundle.
122 123 124 |
# File 'lib/cfbundle/bundle.rb', line 122 def display_name info_string(CFBundle::INFO_KEY_BUNDLE_DISPLAY_NAME) end |
#executable_name ⇒ String?
Returns the name of the bundle’s executable file.
136 137 138 |
# File 'lib/cfbundle/bundle.rb', line 136 def executable_name info_string(CFBundle::INFO_KEY_BUNDLE_EXECUTABLE) end |
#executable_path ⇒ String?
Returns the path of the bundle’s executable file.
The executable’s path is relative to the bundle’s path.
145 146 147 148 |
# File 'lib/cfbundle/bundle.rb', line 145 def executable_path @executable_path ||= executable_name && lookup_executable_path(executable_name) end |
#find_resource(name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) ⇒ Resource?
Returns the first Resource object that matches the specified parameters.
196 197 198 199 200 201 202 203 204 |
# File 'lib/cfbundle/bundle.rb', line 196 def find_resource(name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) Resource.foreach( self, name, extension: extension, subdirectory: subdirectory, localization: localization, preferred_languages: preferred_languages, product: product ).first end |
#find_resources(name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) ⇒ Array
Returns all the Resource objects that matches the specified parameters.
222 223 224 225 226 227 228 229 230 |
# File 'lib/cfbundle/bundle.rb', line 222 def find_resources(name, extension: nil, subdirectory: nil, localization: nil, preferred_languages: [], product: nil) Resource.foreach( self, name, extension: extension, subdirectory: subdirectory, localization: localization, preferred_languages: preferred_languages, product: product ).to_a end |
#identifier ⇒ String?
Returns the bundle identifier from the bundle’s information property list.
82 83 84 |
# File 'lib/cfbundle/bundle.rb', line 82 def identifier info_string(CFBundle::INFO_KEY_BUNDLE_IDENTIFIER) end |
#info ⇒ Hash
Returns the bundle’s information property list hash.
75 76 77 |
# File 'lib/cfbundle/bundle.rb', line 75 def info @info ||= Plist.load_info_plist(self) end |
#localizations ⇒ Array
Returns a list of all the localizations contained in the bundle.
167 168 169 |
# File 'lib/cfbundle/bundle.rb', line 167 def localizations @localizations ||= Localization.localizations_in(self) end |
#name ⇒ String?
Returns the short name of the bundle.
115 116 117 |
# File 'lib/cfbundle/bundle.rb', line 115 def name info_string(CFBundle::INFO_KEY_BUNDLE_NAME) end |
#package_type ⇒ String?
Returns the bundle’s OS Type code.
The value for this key consists of a four-letter code.
108 109 110 |
# File 'lib/cfbundle/bundle.rb', line 108 def package_type info_string(CFBundle::INFO_KEY_BUNDLE_PACKAGE_TYPE) end |
#preferred_localizations(preferred_languages) ⇒ Array
Returns an ordered list of preferred localizations contained in the bundle.
176 177 178 |
# File 'lib/cfbundle/bundle.rb', line 176 def preferred_localizations(preferred_languages) Localization.preferred_localizations(localizations, preferred_languages) end |
#release_version ⇒ String?
Returns the bundle’s release version number.
96 97 98 |
# File 'lib/cfbundle/bundle.rb', line 96 def release_version info_string(CFBundle::INFO_KEY_BUNDLE_SHORT_VERSION_STRING) end |
#resources_directory ⇒ String
Returns the path of the bundle’s subdirectory that contains its resources.
The path is relative to the bundle’s path. For iOS application bundles, as the resources directory is the bundle, this method returns a single dot (.
).
157 158 159 160 161 162 163 |
# File 'lib/cfbundle/bundle.rb', line 157 def resources_directory case layout_version when 0 then 'Resources' when 2 then 'Contents/Resources' when 3 then '.' end end |