Class: Exer::Make
Overview
Make class handle all the logic that we need to make binaries. Functions are written to the file and removed after go build. By default all three platforms are used, but you can also exclude each of them.
Constant Summary collapse
- GO =
golang source directory path
File.(__FILE__) .gsub('lib/exer/make.rb', 'go/bin/go').freeze
- PLATFORMS =
%i[linux darwin windows].freeze
Constants included from Template
Template::BINARY_EXIST, Template::FUNCTION, Template::GEM_INSTALL, Template::GEM_RUN, Template::GO_PACKAGES, Template::MAIN_FUNCTION, Template::RUBY_EXEC, Template::RUBY_EXIST, Template::WAIT_FOR_ENTER
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#functions ⇒ Object
readonly
Returns the value of attribute functions.
-
#import ⇒ Object
readonly
Returns the value of attribute import.
-
#main ⇒ Object
readonly
Returns the value of attribute main.
Instance Method Summary collapse
-
#add(function, arg = nil) ⇒ String
(also: #<<)
Add previously defined function to go-main, to be executed.
-
#add_defaults ⇒ Object
Add functions to the go file, and check if ruby is installed.
-
#add_function(function_name) ⇒ String
Define go functions, so we can use them in main.
-
#build(exclude = nil) ⇒ Boolean
Make executable for platforms we want.
-
#initialize(filename) ⇒ Make
constructor
Prepare go file - give it a name and import packages.
-
#wait_for_enter ⇒ Object
Wait for user to press [ENTER] before finish.
Constructor Details
#initialize(filename) ⇒ Make
Prepare go file - give it a name and import packages. This is also a name of final binaries.
35 36 37 38 39 40 41 |
# File 'lib/exer/make.rb', line 35 def initialize(filename) @filename = filename @import = FUNCTION[:go_packages] @main = "\nfunc main() {" @functions = "\n" @wfe = false end |
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
18 19 20 |
# File 'lib/exer/make.rb', line 18 def filename @filename end |
#functions ⇒ Object (readonly)
Returns the value of attribute functions.
16 17 18 |
# File 'lib/exer/make.rb', line 16 def functions @functions end |
#import ⇒ Object (readonly)
Returns the value of attribute import.
16 17 18 |
# File 'lib/exer/make.rb', line 16 def import @import end |
#main ⇒ Object (readonly)
Returns the value of attribute main.
16 17 18 |
# File 'lib/exer/make.rb', line 16 def main @main end |
Instance Method Details
#add(function, arg = nil) ⇒ String Also known as: <<
Add previously defined function to go-main, to be executed.
70 71 72 73 74 |
# File 'lib/exer/make.rb', line 70 def add(function, arg = nil) func = String.new MAIN_FUNCTION[function] func.gsub!('COMMAND', arg) unless arg.nil? @main += "\n#{func}" end |
#add_defaults ⇒ Object
Add functions to the go file, and check if ruby is installed.
109 110 111 112 113 114 |
# File 'lib/exer/make.rb', line 109 def add_defaults %i[binary_exist ruby_exist ruby_exec gem_install gem_run].each do |x| add_function x end add :ruby_exist end |
#add_function(function_name) ⇒ String
Define go functions, so we can use them in main. They are defined in ::Template, and automatically added to file.
54 55 56 |
# File 'lib/exer/make.rb', line 54 def add_function(function_name) @functions += "\n#{FUNCTION[function_name]}" end |
#build(exclude = nil) ⇒ Boolean
Make executable for platforms we want. Functions are written to the file, built into binaries, and file is removed.
If you build binary only with gem_install, do not forget to add wait_for_enter, so user must press enter after installation. Don’t use with :gem_run.
99 100 101 102 103 104 105 |
# File 'lib/exer/make.rb', line 99 def build(exclude = nil) build_binaries exclude true rescue StandardError => e puts e. false end |
#wait_for_enter ⇒ Object
Wait for user to press [ENTER] before finish. Don’t use with :gem_run
119 120 121 |
# File 'lib/exer/make.rb', line 119 def wait_for_enter @wfe = true end |