Class: Application::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/hotcocoa/application/specification.rb

Overview

Inspired by Gem::Specification that is used by Rubygems, this class represents the configuration for a Mac OS X application bundle.

A specification object is used to build your app bundle and define the Info.plist metadata for the application.

Defined Under Namespace

Classes: Error

App Metadata collapse

App Layout collapse

Deployment Options collapse

Deployment Options collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Specification

Returns a new instance of Specification

Yields:

  • (_self)

Yield Parameters:



278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/hotcocoa/application/specification.rb', line 278

def initialize
  default_attributes.each { |key, value| send "#{key}=", value }

  unless block_given?
    msg = 'You must pass a block at initialization to setup the specification'
    raise Error, msg
  end
  yield self

  # @todo should we verify at initialization or defer until building?
  verify!
end

Instance Attribute Details

#agentBoolean

Whether the app is an daemon with UI or a regular app. Optional.

You can use this flag to hide the dock icon for the app; the default value is false so that apps will have a dock icon by default.

Returns:

  • (Boolean)


116
117
118
# File 'lib/hotcocoa/application/specification.rb', line 116

def agent
  @agent
end

#compileBoolean Also known as: compile?

Note:

If you choose to compile, the original source files will be removed.

Whether or not to compile ruby source files when embedding.

Defaults to true.

Returns:

  • (Boolean)


197
198
199
# File 'lib/hotcocoa/application/specification.rb', line 197

def compile
  @compile
end

The copyright string. Recommended.

Examples:

© 2011, Your Company


76
77
78
# File 'lib/hotcocoa/application/specification.rb', line 76

def copyright
  @copyright
end

#data_modelsArray<String>

Path to any Core Data .xcdatamodel directories that need to be compiled and added to the app bundle.

Returns:

  • (Array<String>)


158
159
160
# File 'lib/hotcocoa/application/specification.rb', line 158

def data_models
  @data_models
end

#doc_typesArray<Hash>

The list of document types supported by the application (for document-based applications only). Optional

Returns:

  • (Array<Hash>)


122
123
124
# File 'lib/hotcocoa/application/specification.rb', line 122

def doc_types
  @doc_types
end

#embed_bridgesupportBoolean Also known as: embed_bridgesupport?

Whether or not to embed BridgeSupport files when embedding the MacRuby framework during deployment.

Defaults to false. Useful if you need to deploy the app to OS X 10.6.

Returns:

  • (Boolean)


263
264
265
# File 'lib/hotcocoa/application/specification.rb', line 263

def embed_bridgesupport
  @embed_bridgesupport
end

#gemsArray<Gem::Requirement>

Note:

HotCocoa will automatically be embedded during deployment and is not added to this list.

Array of gem names to embed in the app bundle during deployment.

Returns:

  • (Array<Gem::Requirement>)


207
208
209
# File 'lib/hotcocoa/application/specification.rb', line 207

def gems
  @gems
end

#iconString

Path to the icon file. Recommended.

Returns:

  • (String)


83
84
85
# File 'lib/hotcocoa/application/specification.rb', line 83

def icon
  @icon
end

#identifierString

The app's unique identifier, in reverse DNS form. Required.

Examples:

Identifier for Mail.app

'com.apple.mail'

Returns:

  • (String)


47
48
49
# File 'lib/hotcocoa/application/specification.rb', line 47

def identifier
  @identifier
end

#nameString

Name of the app. Required.

This name should be less than 16 characters long.

Returns:

  • (String)


37
38
39
# File 'lib/hotcocoa/application/specification.rb', line 37

def name
  @name
end

#overwriteBoolean Also known as: overwrite?

Whether or not to always make a clean build of the app.

Defaults to false.

Returns:

  • (Boolean)


273
274
275
# File 'lib/hotcocoa/application/specification.rb', line 273

def overwrite
  @overwrite
end

#plistHash

Any additional plist values that an application could have.

Values here will override attributes set by other plist related attributes.

Empty by default.

Returns:

  • (Hash)


133
134
135
# File 'lib/hotcocoa/application/specification.rb', line 133

def plist
  @plist
end

#resourcesArray<String>

List of resources that will be copied to the Contents/Resources directory inside the app bundle.

Returns:

  • (Array<String>)


145
146
147
# File 'lib/hotcocoa/application/specification.rb', line 145

def resources
  @resources
end

#short_versionString

The short version for the app. Optional.

The short version for an app should be in the standard "$MAJOR.$MINOR.$PATCHLEVEL" format.

Returns:

  • (String)


67
68
69
# File 'lib/hotcocoa/application/specification.rb', line 67

def short_version
  @short_version
end

#signatureString

Four letter code that acts as a signature for the bundle. Optional.

Defaults to '????', and most apps never set this value.

Examples:

TextEdit.app

'ttxt'

Mail.app

'emal'

Returns:

  • (String)


107
108
109
# File 'lib/hotcocoa/application/specification.rb', line 107

def signature
  @signature
end

#sourcesArray<String>

List of source code files that will be copied to the app bundle.

Returns:

  • (Array<String>)


151
152
153
# File 'lib/hotcocoa/application/specification.rb', line 151

def sources
  @sources
end

#stdlibBoolean, Array<String>

Whether to include the Ruby stdlib in the app when embedding MacRuby. Set this to a Boolean to include/exclude the entire standard library from being embedded.

If you want to embed specific files from the standard library, you can do so by setting this attribute a list of the names of libraries you want.

This attribute corresponds to the --[no]-stdlib and --stdlib arguments for macruby_deploy.

Defaults to true.

Examples:


# Nothing
spec.stdlib = false
# Everything
spec.stdlib = true
# Just 'base64', 'matrix', and 'set'
spec.stdlib = ['base64', 'matrix', 'set']

Returns:

  • (Boolean, Array<String>)


186
187
188
# File 'lib/hotcocoa/application/specification.rb', line 186

def stdlib
  @stdlib
end

#typeString

Four letter code identifying the bundle type. Required.

The default value is 'APPL', which specifies that the bundle is an application.

Returns:

  • (String)


93
94
95
# File 'lib/hotcocoa/application/specification.rb', line 93

def type
  @type
end

#versionString

The version of the app, usually including the build number. Recommended.

Defaults to '1.0'.

Returns:

  • (String)


57
58
59
# File 'lib/hotcocoa/application/specification.rb', line 57

def version
  @version
end

Class Method Details

.load(file) ⇒ Application::Specification

Read an app spec from file and return what is evaluated.



24
25
26
# File 'lib/hotcocoa/application/specification.rb', line 24

def self.load file
  eval File.read(file)
end

Instance Method Details

#add_runtime_dependency(dependency, *requirements) ⇒ Object Also known as: add_dependency

Declares a runtime dependency on a gem, with any given version requirements. If the embedding is also set, then any dependent gems will also be embedded into the app bundle.

This method was liberally borrowed from RubyGems project and has the same semantics here as it does for a gem specification.

Examples:


spec.add_runtime_dependency 'hotcocoa', '~> 0.6'


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/hotcocoa/application/specification.rb', line 221

def add_runtime_dependency dependency, *requirements
  requirements = if requirements.empty? then
                   Gem::Requirement.default
                 else
                   requirements.flatten
                 end

  unless dependency.respond_to?(:name) &&
      dependency.respond_to?(:version_requirements)

    dependency = Gem::Dependency.new(dependency, requirements, :runtime)
  end

  gems << dependency
end

#declare_doc_type(&block) ⇒ Object

Examples:


spec.declare_doc_type do |doc_type|
  doc_type.extensions = ["ext"]
  doc_type.icon       = "MyIcon.icns"
  doc_type.name       = "MyProjectDocument"
  doc_type.role       = :editor
  doc_type.class      = "MyDocument"
end


251
252
253
# File 'lib/hotcocoa/application/specification.rb', line 251

def declare_doc_type(&block)
  @doc_types << DocumentTypeSpecification.new(&block)
end

#icon_exists?Boolean

Whether or not the icon exists for this spec.

Returns:

  • (Boolean)


307
308
309
# File 'lib/hotcocoa/application/specification.rb', line 307

def icon_exists?
  @icon ? File.exist?(@icon) : false
end

#verify!Object



291
292
293
294
295
296
297
298
299
300
# File 'lib/hotcocoa/application/specification.rb', line 291

def verify!
  verify_name
  verify_identifier
  verify_version
  verify_short_version
  verify_copyright
  verify_type
  verify_signature
  verify_agent
end