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

Initialize a new loader.



151
152
153
154
155
156
157
158
159
# File 'lib/teapot/loader.rb', line 151

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.



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

def script
  @script
end

Instance Method Details

#changed?Boolean

Whether the teapot file has been modified since it was loaded.

Returns:

  • (Boolean)


171
172
173
# File 'lib/teapot/loader.rb', line 171

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

#reloadObject

Reload the loader with fresh data.



177
178
179
# File 'lib/teapot/loader.rb', line 177

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

#teapot_pathObject

The absolute path to the teapot.rb file for this package.



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

def teapot_path
	@package.path + @path
end