### Manual Setup with Custom Patterns Source: https://context7.com/ruby-next/freezolite/llms.txt Configure Freezolite with custom glob patterns to specify which files should have their string literals frozen. This provides more granular control over the freezing process. ```ruby require "freezolite" # Configure Freezolite with custom patterns Freezolite.setup( # Array of glob patterns for files to freeze patterns: [ File.join(Dir.pwd, "app", "**", "*.rb"), File.join(Dir.pwd, "lib", "**", "*.rb"), File.join(Dir.pwd, "test", "**", "*.rb") ], # Array of glob patterns to exclude exclude_patterns: [ File.join(Dir.pwd, "vendor", "**", "*"), File.join(Dir.pwd, "app", "generated", "**", "*") ] ) # Now load your application code require_relative "app/models/user" # String literals in user.rb will be frozen automatically ``` -------------------------------- ### Release Gem and Push Tags Source: https://github.com/ruby-next/freezolite/blob/master/RELEASING.md Use the `gem release -t` command to build, tag, and push the gem to RubyGems. Ensure tags are also pushed to the remote repository. ```sh gem release -t git push --tags ``` -------------------------------- ### Configure Freezolite with Custom Patterns and Exclusions Source: https://github.com/ruby-next/freezolite/blob/master/README.md Manually configure Freezolite by specifying glob patterns for directories to include and exclude. This is useful when the project root is not the default `Dir.pwd` or when specific subdirectories need to be targeted or ignored. ```ruby require "freezolite" Freezolite.setup( # You must pass a list of glob patterns patterns: ["/path/to/dir1/*.rb", "/path/to/dir2/*.rb"], exclude_patterns: ["/path/to/dir1/vendor/*"] ) ``` -------------------------------- ### Enable Experimental Constant Freezing in Freezolite Source: https://github.com/ruby-next/freezolite/blob/master/README.md Opt-in to the experimental feature for freezing constants by setting `Freezolite.experimental_freeze_constants` to `true` before requiring `freezolite/auto` or setting up manually. This leverages Ruby 3's `# shareable_constant_value` pragma. ```ruby require "freezolite" # You can also specify specific values, such as literal, experimental_copy, etc. # Setting to `true` is equal to the `literal` value. Freezolite.experimental_freeze_constants = true require "freezolite/auto" # or setup manually ``` -------------------------------- ### Enable Experimental Constants Freezing Source: https://context7.com/ruby-next/freezolite/llms.txt Enable experimental constant freezing by setting `Freezolite.experimental_freeze_constants` to true or a specific pragma value before calling Freezolite.setup. This deep-freezes constants like arrays and hashes, making them Ractor-shareable. ```ruby require "freezolite" # Enable experimental constant freezing before setup # true is equivalent to :literal Freezolite.experimental_freeze_constants = true # Or specify a specific pragma value # Freezolite.experimental_freeze_constants = :literal # Freezolite.experimental_freeze_constants = :experimental_copy Freezolite.setup( patterns: [File.join(Dir.pwd, "app", "**", "*.rb")], exclude_patterns: [File.join(Dir.pwd, "vendor", "*")] ) # Now constants in loaded files will be frozen: # module Config # ALLOWED_ORIGINS = ["https://example.com", "https://api.example.com"] # # ALLOWED_ORIGINS is now frozen and immutable # # ALLOWED_ORIGINS << "https://new.com" would raise FrozenError # end ``` -------------------------------- ### Publish Gem using gem-release Source: https://github.com/ruby-next/freezolite/blob/master/RELEASING.md The `gem release -t` command from the `gem-release` gem automates the process of publishing a new version of your gem. ```sh gem release -t ``` -------------------------------- ### Push Code to GitHub Source: https://github.com/ruby-next/freezolite/blob/master/RELEASING.md Push your local changes to the remote GitHub repository to ensure continuous integration checks pass before proceeding with the release. ```sh git push ``` -------------------------------- ### Integrate Freezolite with Bootsnap Source: https://context7.com/ruby-next/freezolite/llms.txt Ensure Freezolite is required after Bootsnap in your `config/boot.rb` file for compatibility with Bootsnap's compilation caching. No manual cache invalidation is necessary. ```ruby # config/boot.rb ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) require "bundler/setup" require "bootsnap/setup" # Bootsnap first # config/application.rb require_relative "boot" require "rails/all" Bundler.require(*Rails.groups) require "freezolite/auto" # Freezolite after Bootsnap module MyApp class Application < Rails::Application end end ``` -------------------------------- ### Require Freezolite Auto Mode in Application Entry Point Source: https://github.com/ruby-next/freezolite/blob/master/README.md In your application's main entry point (e.g., Rails' `config/application.rb`), require `freezolite/auto` after loading dependencies to automatically apply frozen string literals to project files. ```ruby # config/application.rb #... Bundler.require(*Rails.groups) require "freezolite/auto" # ``` -------------------------------- ### Enable Auto Mode in Rails Application Source: https://context7.com/ruby-next/freezolite/llms.txt For Rails applications, require 'freezolite/auto' after Bundler.require and before loading application code to enable automatic freezing for all Ruby files in the current working directory, excluding the vendor/bundle folder. ```ruby require_relative "boot" require "rails/all" Bundler.require(*Rails.groups) # Add this line AFTER Bundler.require and BEFORE loading your application code require "freezolite/auto" module MyApp class Application < Rails::Application # ... application configuration end end ``` -------------------------------- ### Opt Out Individual Files from Freezing Source: https://context7.com/ruby-next/freezolite/llms.txt Files can opt out of Freezolite's automatic freezing by explicitly declaring `# frozen_string_literal: false` and optionally `# shareable_constant_value: none` at the top of the file. This overrides Freezolite's behavior for that specific file. ```ruby # frozen_string_literal: false # shareable_constant_value: none # This file explicitly opts out of Freezolite's freezing class DynamicStringBuilder def build_name(base) result = base.dup # Safe - we're working with a copy result << " suffix" result end end ``` -------------------------------- ### Verify Frozen Strings Source: https://context7.com/ruby-next/freezolite/llms.txt After Freezolite is set up, string literals in matched files will be frozen. Attempting to mutate them will raise a `FrozenError`. You can verify if a string is frozen using the `.frozen?` method. ```ruby require "freezolite/auto" # In a file matching the patterns (e.g., app/models/user.rb): class User DEFAULT_ROLE = "guest" def update_role(new_role) # This would raise FrozenError because DEFAULT_ROLE is frozen # DEFAULT_ROLE << "_admin" # => FrozenError! # Safe alternatives: new_value = DEFAULT_ROLE + "_admin" # Creates new string new_value = "#{DEFAULT_ROLE}_admin" # Creates new string end end # Verify a string is frozen puts "test".frozen? # => true (in matched files) ``` -------------------------------- ### Add Freezolite Gem to Gemfile Source: https://github.com/ruby-next/freezolite/blob/master/README.md Include the Freezolite gem in your project's Gemfile to enable its functionality. ```ruby gem "freezolite" ``` -------------------------------- ### Commit Version Bump Source: https://github.com/ruby-next/freezolite/blob/master/RELEASING.md Commit the version number change in the `version.rb` file. This is a standard Git commit operation. ```sh git commit -m "Bump 1.." ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.