Class: Teapot::Loader

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

Overview

Loads the teapot.rb script and can reload it if it was changed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, package, path = TEAPOT_FILE) ⇒ Loader

Returns a new instance of Loader.



145
146
147
148
149
150
151
152
153
# File 'lib/teapot/loader.rb', line 145

def initialize(context, package, path = TEAPOT_FILE)
	@context = context
	@package = package
	
	@path = path
	@mtime = nil
	
	@script, @mtime = load!
end

Instance Attribute Details

#scriptObject (readonly)

Returns the value of attribute script.



155
156
157
# File 'lib/teapot/loader.rb', line 155

def script
  @script
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/teapot/loader.rb', line 161

def changed?
	File.mtime(teapot_path) > @mtime
end

#reloadObject



165
166
167
# File 'lib/teapot/loader.rb', line 165

def reload
	self.class.new(@context, @package, @path)
end

#teapot_pathObject



157
158
159
# File 'lib/teapot/loader.rb', line 157

def teapot_path
	@package.path + @path
end