class Loader
Loads the teapot.rb script and can reload it if it was changed.
Definitions
def initialize(context, package, path = TEAPOT_FILE)
Initialize a new loader.
Signature
-
parameter
contextContext The project context.
-
parameter
packagePackage The package.
-
parameter
pathString The teapot file path.
Implementation
def initialize(context, package, path = TEAPOT_FILE)
@context = context
@package = package
@path = path
@mtime = nil
@script, @mtime = load!
end
def teapot_path
The absolute path to the teapot.rb file for this package.
Signature
-
returns
Build::Files::Path The teapot file path.
Implementation
def teapot_path
@package.path + @path
end
def changed?
Whether the teapot file has been modified since it was loaded.
Signature
-
returns
Boolean True if changed.
Implementation
def changed?
File.mtime(teapot_path) > @mtime
end
def reload
Reload the loader with fresh data.
Signature
-
returns
Loader A new loader instance.
Implementation
def reload
self.class.new(@context, @package, @path)
end
def load!(path = teapot_path)
Load a teapot.rb file relative to the root of the @package.
Implementation
def load!(path = teapot_path)
raise MissingTeapotError.new(path) unless File.exist?(path)
script = Script.new(@context, @package)
mtime = File.mtime(path)
script.instance_eval(path.read, path.to_s)
if script.version == nil
raise IncompatibleTeapotError.new(@package, "<unspecified>")
end
return script, mtime
end