
Security News
Django Joins curl in Pushing Back on AI Slop Security Reports
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
A preprocessor system for Ruby.
Onload makes it possible to preprocess Ruby files before they are loaded into the interpreter. It works with plain 'ol Ruby code, within Rails, or wherever Zeitwerk is used.
Preprocessing has been around for a long time in the C world. The idea is to be able to compile the code differently depending on operating system, architecture, etc. In interpreted languages, preprocessing is most useful for transpilation, i.e. converting code from one dialect to another. Maybe the most familiar example of this is translating TypeScript to JavaScript. The JavaScript interpreters inside web browsers and Node.js can't run TypeScript directly - it has to be converted into JavaScript first.
In the JavaScript ecosystem it's very common for your code to pass through a build step, but not so in Ruby. That's where onload comes in.
Onload lets you transform Ruby code just before it's loaded into the Ruby interpreter. You give it a file extension and a callable object, and it does the rest. Onload is the transpilation system behind rux, a tool that let's you write HTML tags inside your view components (think if it like jsx for Ruby).
Let's write an (admittedly contrived) preprocessor that upcases literal strings in Ruby files. We'll use the file extension .up to indicate which files to process.
Preprocessors can be any Ruby object that responds to the #call
method.
class UpcasePreprocessor
def self.call(source)
source.gsub(/(\"\w+\")/, '\1.upcase')
end
end
Next we'll tell onload about our preprocessor.
Onload.register(".up", UpcasePreprocessor)
Finally, we'll load the necessary monkeypatches by "installing" onload into the interpreter. In Rails environments you can skip this step, as it is done for you via the included railtie.
Onload.install!
Now, the contents of any file with a .up file extension will be passed to UpcasePreprocessor.call
. The return value will be written to a separate Ruby file and loaded instead of the original .up file.
If you're using asdf, run ./script/run_appraisal.rb
to run Rails and plain Ruby tests for all supported versions.
Otherwise, use Appraisal to run tests for Rails or plain ruby:
bundle exec appraisal ruby rake spec:ruby
bundle exec appraisal <version> rake spec:rails
. Run bundle exec appraisal list
to see the available versions. To run tests for Rails 7.0, try bundle exec appraisal rails-7.0 rake spec:rails
Licensed under the MIT license. See LICENSE for details.
FAQs
Unknown package
We found that onload demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.