Class: Gamefic::Sdk::Tasks::Ruby

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/gamefic-sdk/tasks/ruby.rb

Overview

Tasks for running and building Ruby apps.

Instance Attribute Summary

Attributes included from Common

#directory

Instance Method Summary collapse

Methods included from Common

#absolute_path, #initialize

Instance Method Details

#buildObject

Build a distributable Ruby app.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gamefic-sdk/tasks/ruby.rb', line 24

def build
  current = $LOADED_FEATURES.clone
  require_relative File.join(absolute_path, 'main')
  loaded = ($LOADED_FEATURES - current)
  exports = {}
  exports.merge! append_gem('gamefic')
  exports.merge! append_gem('gamefic-tty')
  loaded.each do |path|
    exports.merge! relativize(path)
  end
  files = {}
  exports.each_pair do |rel, full|
    files[rel] = Base64.encode64(Zlib::Deflate.deflate(File.read(full)))
  end
  program = program_code(files)
  FileUtils.mkdir_p File.join(absolute_path, 'builds', 'ruby')
  File.write(File.join(absolute_path, 'builds', 'ruby', "#{File.basename(absolute_path)}.rb"), program)
end

#runObject

Run a command-line Ruby app.



17
18
19
20
# File 'lib/gamefic-sdk/tasks/ruby.rb', line 17

def run
  require_relative File.join(absolute_path, 'main')
  Gamefic::Tty::Engine.run
end