Class: LowLoad::RBXAdapter
- Defined in:
- lib/adapters/rbx_adapter.rb
Constant Summary collapse
- EXTENSIONS =
['rbx']
Instance Method Summary collapse
-
#evaluate(file_path:) ⇒ Object
Now we can load the file into Ruby.
-
#metadata(file_path:) ⇒ Object
Map all definitions and dependencies.
-
#preload(file_path:) ⇒ Object
Then autoload all dependencies for those files.
Instance Method Details
#evaluate(file_path:) ⇒ Object
Now we can load the file into Ruby.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/adapters/rbx_adapter.rb', line 28 def evaluate(file_path:) # 1. "File Load" phase. file_proxy = Lowkey[file_path] || Lowkey.load(file_path) templates = wrap_render_methods(file_proxy:) # 2. "Class Load" phase. # Not a security risk because "eval" is equivalent to "load" or "require_relative" in this context. eval(file_proxy.export, top_level_binding, file_proxy.file_path, 0) # rubocop:disable Security/Eval # 3. "Runtime" phase (before low nodes are rendered). # Templates only exist if antlers gem has been required by another gem (such as LowNode) and the template contains antlers syntax. templates.each do |namespace, method_template| klass = Object.const_get(namespace) method, template = method_template # TODO: If params contain "**props" or similar then send that, so that LowNode can replicate it. params = method.params.map(&:name) next unless supports_templates?(klass) || raise(UnsupportedTemplate, "Template for '#{namespace}' identified but not implemented") # TODO: Make template engine configurable. klass.build_template(template:, params:, engine: Antlers, namespace:) end end |
#metadata(file_path:) ⇒ Object
Map all definitions and dependencies.
16 17 18 19 20 |
# File 'lib/adapters/rbx_adapter.rb', line 16 def (file_path:) Lowkey.load(file_path) { file_path: } end |
#preload(file_path:) ⇒ Object
Then autoload all dependencies for those files.
23 24 25 |
# File 'lib/adapters/rbx_adapter.rb', line 23 def preload(file_path:) Loader.add_autoloads(file_proxy: Lowkey[file_path]) end |