Class: Application::Builder

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

Overview

This class is responsible for building application bundles, but could theoretically be used to build other bundles, such as frameworks, with only a few changes.

It is designed to work in conjunction with an Specification object which would provide details on how to build the bundle.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Builder) initialize(spec)

A new instance of Builder



35
36
37
38
39
40
41
42
# File 'lib/hotcocoa/application/builder.rb', line 35

def initialize spec
  @spec = case spec
          when Specification
            spec
          when String
            Specification.load spec
          end
end

Instance Attribute Details

- (Application::Specification) spec (readonly)

Cached spec.



32
33
34
# File 'lib/hotcocoa/application/builder.rb', line 32

def spec
  @spec
end

Class Method Details

+ (Object) build(spec, opts = {})

Build an application from a specification, optionally for deployment.

Parameters:

Options Hash (opts):

  • :deploy (Symbol) — default: false


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

def self.build spec, opts = {}
  new(spec).build(opts)
end

Instance Method Details

- (Object) build(opts = {})

Parameters:

  • (Hash)
  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :deploy (Symbol) — default: false


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/hotcocoa/application/builder.rb', line 46

def build opts = {}
  if spec.overwrite? || opts[:deploy] # Deploying always makes a fresh build
    remove_bundle_root
  end
  build_bundle_structure
  write_bundle_files
  copy_sources
  copy_resources
  compile_data_models
  copy_icon_file if spec.icon_exists?
  deploy if opts[:deploy]
end

- (Object) remove_bundle_root

Destroy the existing bundle, if it exists.



68
69
70
# File 'lib/hotcocoa/application/builder.rb', line 68

def remove_bundle_root
  FileUtils.rm_rf bundle_root if File.exist?(bundle_root)
end

- (Object) run

Run the bundle's binary directly so STDOUT and STDERR appear in the terminal.



62
63
64
# File 'lib/hotcocoa/application/builder.rb', line 62

def run
  `"./#{executable_file}"`
end