Module: Zui::Dist

Defined in:
lib/zui/dist_config.rb

Defined Under Namespace

Classes: Builder, Config

Constant Summary collapse

CONFIG_FILE =
"config.rb"
UNSET =
Object.new.freeze
PLATFORM_ICON_EXTENSIONS =
{
  linux: %w[.png .svg],
  macos: %w[.icns],
  windows: %w[.ico]
}.freeze

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object

Raises:

  • (ArgumentError)


151
152
153
154
155
156
157
# File 'lib/zui/dist_config.rb', line 151

def configure(&block)
  raise ArgumentError, "Dist.configure requires a block" unless block

  builder = Builder.new
  block.arity == 1 ? block.call(builder) : builder.instance_eval(&block)
  builder.build
end

.load(project:, platform: Platform.current) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/zui/dist_config.rb', line 159

def load(project:, platform: Platform.current)
  project = File.expand_path(project)
  path = File.join(project, CONFIG_FILE)
  raise ArgumentError, "#{CONFIG_FILE} not found in project root" unless File.file?(path)
  raise ArgumentError, "#{CONFIG_FILE} is too large" if File.size(path) > 131_072

  value = Module.new.module_eval(File.read(path), path, 1)
  unless value.is_a?(Config)
    raise ArgumentError, "#{CONFIG_FILE} must return Zui::Dist.configure do ... end"
  end
  value.validate!(project:, platform: platform.assert_supported!)
rescue SyntaxError => error
  raise ArgumentError, "invalid #{CONFIG_FILE}: #{error.message.lines.first.to_s.strip}"
rescue ScriptError => error
  raise ArgumentError, "#{CONFIG_FILE} failed: #{error.class}: #{error.message}"
rescue ArgumentError
  raise
rescue StandardError => error
  raise ArgumentError, "#{CONFIG_FILE} failed: #{error.class}: #{error.message}"
end