Class: IncludeJS::Env
- Inherits:
-
Object
- Object
- IncludeJS::Env
- Defined in:
- lib/include_js.rb
Instance Attribute Summary collapse
-
#root_path ⇒ Object
FIXME Make this act like a PATH (see Modules 1.1 require.paths) and think about the API.
Instance Method Summary collapse
-
#initialize ⇒ Env
constructor
A new instance of Env.
- #module(module_id) ⇒ Object
- #require(module_id, globals = {}) ⇒ Object
Constructor Details
#initialize ⇒ Env
Returns a new instance of Env.
17 18 19 20 21 |
# File 'lib/include_js.rb', line 17 def initialize @root_path = File.('.') @modules = {} # This stores all loaded modules by their absolute path (not their id) @engine = V8::Context.new end |
Instance Attribute Details
#root_path ⇒ Object
FIXME Make this act like a PATH (see Modules 1.1 require.paths) and think about the API
15 16 17 |
# File 'lib/include_js.rb', line 15 def root_path @root_path end |
Instance Method Details
#module(module_id) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/include_js.rb', line 27 def module(module_id) result = Module.new require(module_id).each do |name, method| result.send(:define_method, name) do |*args| method.call(*args) end end result end |
#require(module_id, globals = {}) ⇒ Object
23 24 25 |
# File 'lib/include_js.rb', line 23 def require(module_id, globals={}) load_module(module_id, globals, nil) end |