Class: Livecode::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/livecode/loader.rb

Overview

Handles (re)loading of library files, which is mostly useful for development.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.



8
9
10
11
# File 'lib/livecode/loader.rb', line 8

def initialize
	@reloadable_files = []
	@reloading = false
end

Instance Attribute Details

#reloadable_filesObject

Returns the value of attribute reloadable_files.



6
7
8
# File 'lib/livecode/loader.rb', line 6

def reloadable_files
  @reloadable_files
end

Instance Method Details

#add_reloadable(file) ⇒ Object



13
14
15
16
# File 'lib/livecode/loader.rb', line 13

def add_reloadable(file)
	file = parse_path(file)
	@reloadable_files << file unless @reloadable_files.include?(file)
end

#load_file(file, force = false) ⇒ Object



18
19
20
21
22
23
# File 'lib/livecode/loader.rb', line 18

def load_file(file, force=false)
	file = parse_path(file)
	return false if @reloading && !force && @reloadable_files.include?(file)
	add_reloadable file
	load("#{file}.rb")
end

#parse_path(path) ⇒ Object



35
36
37
# File 'lib/livecode/loader.rb', line 35

def parse_path(path)
	path.gsub(/\.rb$/, '').gsub(/^\.\//, '')
end

#reload!Object



25
26
27
28
29
30
31
32
33
# File 'lib/livecode/loader.rb', line 25

def reload!
	puts "Reloading: #{@reloadable_files.inspect}"
	@reloading = true
	old_v = $-v; $-v = nil # Temporarily disable warnings
	results = @reloadable_files.map{ |f| load_file( f, true ) }
	$-v = old_v # Re-enable eventual warnings
	@reloading = false
	return results
end