Module: Shoes::Package::Configuration

Extended by:
Furoshiki::Util
Defined in:
shoes-package/lib/shoes/package/configuration.rb

Overview

Configuration for Shoes packagers.

Examples:

config_file = '/path/to/app.yaml'
config = Shoes::Package::Configuration.load(config_file)

Constant Summary collapse

JAR_APP_TEMPLATE_URL =
'https://s3.amazonaws.com/net.wasnotrice.shoes/wrappers/shoes-app-template-0.0.2.zip'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.config_for_single_file_app(pathname) ⇒ Object

If it exists, load default options. If not, let the filesystem raise an error.



119
120
121
122
123
124
125
126
127
# File 'shoes-package/lib/shoes/package/configuration.rb', line 119

def self.config_for_single_file_app(pathname)
  default_options = {
    run: pathname.basename.to_s,
    name: pathname.basename(pathname.extname).to_s.gsub(/\W/, '-')
  }.to_yaml
  options = pathname.exist? ? default_options : pathname
  dummy_file = Struct.new(:read)
  [dummy_file.new(options), pathname.parent]
end

.create(config = {}) ⇒ Object

Parameters:

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

    user options



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'shoes-package/lib/shoes/package/configuration.rb', line 88

def self.create(config = {})
  defaults = {
    name: 'Shoes App',
    version: '0.0.0',
    release: 'Rookie',
    run: nil,
    ignore: 'pkg',
    # TODO: Add actual paths. Keep these keys for compatibility with Shoes 3
    icons: {
      # osx: 'path/to/default/App.icns',
      # gtk: 'path/to/default/app.png',
      # win32: 'path/to/default/App.ico',
    },
    # TODO: Add actual paths. Keep these keys for compatibility with Shoes 3
    dmg: {
      # ds_store: 'path/to/default/.DS_Store',
      # background: 'path/to/default/background.png'
    },
    working_dir: Dir.pwd,
    gems: ['shoes-core'],
    validator: Validator,
    warbler_extensions: WarblerExtensions
  }

  symbolized_config = deep_symbolize_keys(config)
  symbolized_config[:gems] = merge_gems(defaults, symbolized_config)
  Furoshiki::Configuration.new defaults.merge(symbolized_config)
end

.load(path, base_config) ⇒ Object .load(path) ⇒ Object .load(path) ⇒ Object

Convenience method for loading config from a file. Note that you can pass four kinds of paths to the loader. Given the following file structure:

|– a | |– app.yaml | |– shoes-app-a.rb | |– b |– shoes-app-b.rb

To package an app that has an ‘app.yaml`, like `shoes-app-a.rb`, you can call the loader with any of:

  • a/app.yaml

  • a

  • a/shoes-app-a.rb

These will all find and use your configuration in ‘a/app.yaml`. To package an app that does not have an `app.yaml`, like `b/shoes-app-b.rb`, you must call the loader with the path of the script itself. Note that without an `app.yaml`, you will only bundle a single file, and your app will simply use the Shoes app icon.

Overloads:

  • .load(path, base_config) ⇒ Object

    Parameters:

    • path (String)

      location of the app’s ‘app.yaml’

    • base_config (Hash)

      default values

  • .load(path) ⇒ Object

    Parameters:

    • path (String)

      location of the directory that contains the app’s ‘app.yaml’

    • base_config (Hash)

      default values

  • .load(path) ⇒ Object

    Parameters:

    • path (String)

      location of the app

    • base_config (Hash)

      default values



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'shoes-package/lib/shoes/package/configuration.rb', line 63

def self.load(path, base_config = {})
  pathname = Pathname.new(path)
  app_yaml = Pathname.new('app.yaml')

  if pathname.basename == app_yaml
    file = pathname
    dir = pathname.dirname
  elsif pathname.directory?
    file = pathname.join(app_yaml)
    dir = pathname
  elsif pathname.file? && pathname.parent.children.include?(pathname.parent.join(app_yaml))
    file = pathname.parent.join(app_yaml)
    dir = pathname.parent
  else
    file, dir = config_for_single_file_app(pathname)
  end

  config = YAML.safe_load(file.read, [Symbol])
  config[:working_dir] = dir
  config[:gems] = merge_gems(base_config, config)
  config[:gems] << "shoes-swt"
  create(config)
end

.merge_gems(base, additional) ⇒ Object

We want to retain all of the gems, but simply merging the hash will replace the whole array, so we handle the gems separately. Note that keys may not have been symbolized yet



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'shoes-package/lib/shoes/package/configuration.rb', line 132

def self.merge_gems(base, additional)
  base_gems = begin
                base.fetch(:gems)
              rescue
                base['gems']
              end
  additional_gems = begin
                      additional.fetch(:gems)
                    rescue
                      additional['gems']
                    end
  Array(base_gems).concat(Array(additional_gems)).uniq
end

Instance Method Details

#backendObject



22
23
24
# File 'shoes-package/lib/shoes/package/configuration.rb', line 22

def backend
  "swt"
end