Class: Rubuild::Load::Loader
- Inherits:
-
Object
- Object
- Rubuild::Load::Loader
- Defined in:
- lib/rubuild/load/loader.rb
Overview
Rubuild::Load::Loader Load code into a private execution context, referenced by a String name.
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
-
#_loadInternal(env, text, path, name, fname) ⇒ Object
Rubuild::Load::Loader#loadFile.
-
#findFile(fname) ⇒ Object
Rubuild::Load::Loader#provision.
-
#initialize(ns_factory) ⇒ Loader
constructor
A new instance of Loader.
-
#loadFile(env, path, name = path) ⇒ Object
Rubuild::Load::Loader#findFile.
-
#loadString(env, text, name) ⇒ Object
Rubuild::Load::Loader#loadFile.
-
#provision(env, key) ⇒ Object
Rubuild::Load::Loader#initialize.
Constructor Details
#initialize(ns_factory) ⇒ Loader
Returns a new instance of Loader.
33 34 35 36 |
# File 'lib/rubuild/load/loader.rb', line 33 def initialize(ns_factory) self.rubuild_load_loader__ns_factory = ns_factory self.rubuild_load_loader__inc_paths = Array.new end |
Instance Method Details
#_loadInternal(env, text, path, name, fname) ⇒ Object
Rubuild::Load::Loader#loadFile
66 67 68 69 70 71 72 |
# File 'lib/rubuild/load/loader.rb', line 66 def _loadInternal(env, text, path, name, fname) info = Rubuild::Load::Info.new(env, path, name) ns = self.ns_factory.create ns.rubuild_info = info ns.class_eval(text, fname) info.location end |
#findFile(fname) ⇒ Object
Rubuild::Load::Loader#provision
46 47 48 49 50 51 52 53 54 |
# File 'lib/rubuild/load/loader.rb', line 46 def findFile(fname) if ! self.frozen? raise Error::Unprovisioned.new(self, :findFile) end Rubuild::Util.enumerable_find(self.rubuild_load_loader__inc_paths) do |path| testfile = "#{path}/#{fname}" File.exists?(testfile) && testfile end end |
#loadFile(env, path, name = path) ⇒ Object
Rubuild::Load::Loader#findFile
56 57 58 59 60 |
# File 'lib/rubuild/load/loader.rb', line 56 def loadFile(env, path, name = path) fname = self.findFile(path) text = File.open(fname, 'r') do |f| f.read end self._loadInternal(env, text, path, name, fname) end |
#loadString(env, text, name) ⇒ Object
Rubuild::Load::Loader#loadFile
62 63 64 |
# File 'lib/rubuild/load/loader.rb', line 62 def loadString(env, text, name) self._loadInternal(env, text, name, name, name) end |
#provision(env, key) ⇒ Object
Rubuild::Load::Loader#initialize
38 39 40 41 42 43 44 |
# File 'lib/rubuild/load/loader.rb', line 38 def provision(env, key) self.freeze self.rubuild_load_loader__inc_paths.freeze l = Rubuild::Env::Location.new("#{self.class.to_s}\#provision(#{key})", env.build_factory) l.set_data(self) env.provide(key, l) end |