Class: LowLoad::RBXAdapter

Inherits:
Adapter
  • Object
show all
Defined in:
lib/adapters/rbx_adapter.rb

Constant Summary collapse

EXTENSIONS =
['rbx'].freeze

Instance Method Summary collapse

Instance Method Details

#evaluate(file_path:) ⇒ Object

Now we can load the file into Ruby.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/adapters/rbx_adapter.rb', line 26

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 (like 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

#mapload(file_path:) ⇒ Object

Map all definitions and dependencies.



16
17
18
# File 'lib/adapters/rbx_adapter.rb', line 16

def mapload(file_path:)
  Lowkey.load(file_path)
end

#preload(file_path:) ⇒ Object

Then autoload all dependencies for those files.



21
22
23
# File 'lib/adapters/rbx_adapter.rb', line 21

def preload(file_path:)
  Loader.add_autoloads(file_proxy: Lowkey[file_path])
end