Project

lowload

0.0
No release in over 3 years
An autoloader that lets you use any module namespace convention with any folder structure and mix in manual require statements.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Runtime

>= 0
 Project Readme

Gem version GitHub repo Codeberg repo

LowLoad

LowLoad is really dumb; like a bull in a china shop, smashing through fragile dependencies to autoload your code without manual load/require/require_relative calls.

  1. First LowLoad goes through all your files and notes their constant definitions
  2. Then it goes through the same files again and creates autoloads for those dependencies
  3. Then it goes through every file again and loads it into Ruby

This approach results in a very flexible autoloader with no conventions to follow, no internal dependency graph and very little configuration needed... just point it at a directory.

Features:

  • Use any namespace structure you want (namespaces are not inferred from folder structure)
  • Mix in manual requires in autoloaded files
  • Supports RBX files

Usage

lowload()

Load an .rb or .rbx file with:

LowLoad.lowload('spec/fixtures/html_node.rbx')

dirload()

Load an entire directory with:

LowLoad.dirload(File.expand_path('app', __FILE__))

File Support

LowLoad supports normal Ruby (.rb) files as well as a few other embedded formats.

RBX

LowLoad supports loading RBX files (.rbx). RBX files are Ruby files containing unescaped HTML markup:

class MyClass
  def render
    <p>Hello</p>
  end
end

ℹ️ For more information see LowNode.

Antlers

Antlers syntax can be embedded inside the render method of your RBX file:

class ParentNode
  def render
    <p><{ ChildNode }></p>
  end
end

ℹ️ For more information see Antlers.

Philosophy

  • Folders are often organised by the kind of file it is, a bunch of views for example. But namespaces should be organised by your domain — different to your file structure
  • You should be able to mix autoloading with manual require and require_relative calls. You often need files outside the autoloaded directory

Caveats

Like other autoloading libraries, LowLoad doesn't support circular dependencies on class load (runtime is fine).

❌ Please don't do:

class A
  include B
end

class B
  include A
end

✅ Instead do:

class A
  include C
end

class B
  include C
end

class C
  # Code that both A and B share.
end

Installation

Add gem 'lowload' to your Gemfile then:

bundle install