AutoFreeze
Sets the frozen_string_literal compile option for your gems.
Installation
- In your Gemfile, add this:
gem 'auto_freeze'
- Run
bundle installas normal.
Usage
Before the Bundler.require in your application, configure the gems to be
required with the frozen_string_literal compile option set to true.
By default, all gems are required with frozen strings.
AutoFreeze.setup!
Bundler.require(*Rails.groups)
You can exclude certain gems:
exclude_gems = %w[
arr-pm-0.0.12
email_reply_trimmer-0.1.6
method_source-1.0.0
seed-fu-2.3.9
unicode_utils-1.4.0
].freeze
AutoFreeze.setup!(excluded_gems: exclude_gems)
Bundler.require(*Rails.groups)
To only freeze gems you specify, pass an array into auto_freeze option:
AutoFreeze.setup!(auto_freeze: %w[httpclient-2.9.0])
Bundler.require(*Rails.groups)
AutoFreeze will automatically set frozen_string_literal compile option to be
true when that gem is required by Bundler.
Development
After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.
Thanks
Thanks to
https://evilmartians.com/chronicles/freezolite-the-magic-gem-for-keeping-ruby-literals-safely-frozen
for the research showing that it was possible to dynamically enable the frozen_string_literal option.