Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

masover-autoloader

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

masover-autoloader

  • 0.0.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

A couple of handy features to enhance Kernel#autoload.

Features

  • Fire Kernel#autoload at an entire directory
  • Fire it again at a subdirectory, for namespace'd models

Motivation/Examples

I was using Ramaze as a web framework, and discovered that the standard Ramaze way of loading a directory of files is to slurp them all (with 'acquire'). I decided I'd rather use autoload, and not load things I'm not using. But I wasn't really looking forward to this:

autoload :User, 'model/user' autoload :Clan, 'model/clan' autoload :Item, 'model/item'

...ad nauseum. So, the first feature is a shallow, directory-based autoload:

AutoLoader << 'model'

Of course, being a pedant, I like to namespace my models. I don't want to slurp the entire directory tree. Instead, you can do this:

class User < MyFavoriteORM::Model include AutoLoader ... end

Now, all AutoLoaded paths will be searched for a subdirectory called 'user', and all files within will be autoloaded. Just as if you'd done:

User.autoload :Anonymous, 'model/user/anonymous' User.autoload :Registered, 'model/user/registered'

Of course, there's no requirement that you have a base class, or anything of the sort. If you just want a namespace, you can always do:

module MyNamespace; include AutoLoader; end

And you're done.

Compatibility

Currently, Merb's extlib and Rails' activesupport are supported. It should be trivial to interface with other libraries.

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc