diff --git a/CHANGELOG.md b/CHANGELOG.md index 632bf41..2554665 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ### next -* TODO: Replace this bullet point with an actual description of a change. +* Switched to Zeitwerk as autoloader (#7) ### 1.5.0 (3 January 2025) diff --git a/keyless.gemspec b/keyless.gemspec index 8ddfa8c..85b5c8f 100644 --- a/keyless.gemspec +++ b/keyless.gemspec @@ -39,4 +39,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'httparty', '>= 0.21' spec.add_dependency 'jwt', '~> 2.6' spec.add_dependency 'recursive-open-struct', '~> 2.0' + spec.add_dependency 'zeitwerk', '~> 2.6' end diff --git a/lib/keyless.rb b/lib/keyless.rb index 31c5458..8c55245 100644 --- a/lib/keyless.rb +++ b/lib/keyless.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'zeitwerk' require 'active_support' require 'active_support/concern' require 'active_support/configurable' @@ -8,38 +9,48 @@ require 'active_support/time' require 'active_support/time_with_zone' require 'jwt' -require 'keyless/version' -require 'keyless/configuration' -require 'keyless/jwt' -require 'keyless/rsa_public_key' +require 'recursive-open-struct' +require 'singleton' +require 'openssl' +require 'httparty' # The JWT authentication concern. module Keyless - extend ActiveSupport::Concern + # Setup a Zeitwerk autoloader instance and configure it + loader = Zeitwerk::Loader.for_gem + + # Finish the auto loader configuration + loader.setup + + # Load standalone code + require 'keyless/version' + + # Make sure to eager load all SDK constants + loader.eager_load class << self attr_writer :configuration - end - # Retrieve the current configuration object. - # - # @return [Configuration] - def self.configuration - @configuration ||= Configuration.new - end + # Retrieve the current configuration object. + # + # @return [Configuration] + def configuration + @configuration ||= Configuration.new + end - # Configure the concern by providing a block which takes - # care of this task. Example: - # - # Keyless.configure do |conf| - # # conf.xyz = [..] - # end - def self.configure - yield(configuration) - end + # Configure the concern by providing a block which takes + # care of this task. Example: + # + # Keyless.configure do |conf| + # # conf.xyz = [..] + # end + def configure + yield(configuration) + end - # Reset the current configuration with the default one. - def self.reset_configuration! - self.configuration = Configuration.new + # Reset the current configuration with the default one. + def reset_configuration! + self.configuration = Configuration.new + end end end diff --git a/lib/keyless/jwt.rb b/lib/keyless/jwt.rb index 21302cf..e524dc8 100644 --- a/lib/keyless/jwt.rb +++ b/lib/keyless/jwt.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'recursive-open-struct' - module Keyless # A easy to use model for verification of JSON Web Tokens. This is just a # wrapper class for the excellent ruby-jwt gem. It's completely up to you diff --git a/lib/keyless/rsa_public_key.rb b/lib/keyless/rsa_public_key.rb index 0efb66b..271a602 100644 --- a/lib/keyless/rsa_public_key.rb +++ b/lib/keyless/rsa_public_key.rb @@ -1,9 +1,5 @@ # frozen_string_literal: true -require 'singleton' -require 'openssl' -require 'httparty' - module Keyless # A common purpose RSA public key fetching/caching helper. With the help # of this class you are able to retrieve the RSA public key from a remote