Skip to content

Commit

Permalink
Switched to Zeitwerk as autoloader. (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann Mayer <[email protected]>
  • Loading branch information
Jack12816 authored Jan 11, 2025
1 parent 968eb54 commit 96e8a6c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
1 change: 1 addition & 0 deletions keyless.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 35 additions & 24 deletions lib/keyless.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'zeitwerk'
require 'active_support'
require 'active_support/concern'
require 'active_support/configurable'
Expand All @@ -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
2 changes: 0 additions & 2 deletions lib/keyless/jwt.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/keyless/rsa_public_key.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 96e8a6c

Please sign in to comment.