Skip to content

low-rb/lowload

Repository files navigation

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

About

An autoloader where folders don't have to follow namespaces. Where you can mix and match autoloading and manual requires

Resources

License

Stars

Watchers

Forks

Packages