forked from RMEx/buildozer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts-loader.rb
62 lines (56 loc) · 2.26 KB
/
scripts-loader.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
#==============================================================================
# ** scripts-loader v1.1.0
#------------------------------------------------------------------------------
# By Joke @biloumaster <[email protected]>
# GitHub: https://github.com/RMEx/scripts-externalizer
#------------------------------------------------------------------------------
# Load all scripts from the given folder
# See the README.md on GitHub!
#==============================================================================
#==============================================================================
# ** CONFIGURATION
#==============================================================================
module XT_CONFIG
LOAD_FROM = "Scripts" # Load the scripts from the folder you want.
# Can be "C:/.../MyScripts/" or "../../MyScripts/"
end
#==============================================================================
# ** Loader
#------------------------------------------------------------------------------
# Load all scripts
#==============================================================================
module Loader
#--------------------------------------------------------------------------
# * Extend self
#--------------------------------------------------------------------------
extend self
#--------------------------------------------------------------------------
# * Run the loader
#--------------------------------------------------------------------------
def run
read_list(XT_CONFIG::LOAD_FROM + "/")
end
#--------------------------------------------------------------------------
# * Read a file
#--------------------------------------------------------------------------
def read(file)
File.open(file, 'r') { |f| f.read }
end
#--------------------------------------------------------------------------
# * Read a list and load all the elements
#--------------------------------------------------------------------------
def read_list(path)
@list = read(path + "_list.rb").split("\n")
@list.each do |e|
e.strip!
next if e[0] == "#"
if e[-1] == "/"
read_list(path + e)
else
Kernel.send(:load, path + e + ".rb")
end
end
end
end
Loader.run