keycloak_ruby 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,62 +1,56 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # lib/keycloak_ruby/version.rb
4
- # Module for interacting with Keycloak
5
4
  module KeycloakRuby
6
- # Version module following Semantic Versioning 2.0 guidelines
7
- # Provides detailed version information and helper methods
5
+ # The current version of the KeycloakRuby gem as a string.
6
+ # Follows Semantic Versioning 2.0 (https://semver.org)
7
+ # @example
8
+ # KeycloakRuby::VERSION # => "0.1.3"
9
+ VERSION = "0.1.3"
10
+
11
+ # Provides version information and comparison methods for the KeycloakRuby gem.
12
+ # This module follows Semantic Versioning 2.0 guidelines.
8
13
  #
9
14
  # @example Getting version information
10
- # KeycloakRuby::Version::VERSION # => "0.1.0"
11
- # KeycloakRuby::Version.to_a # => [0, 1, 0]
12
- # KeycloakRuby::Version.to_h # => { major: 0, minor: 1, patch: 0, pre: nil }
13
- # KeycloakRuby.version # => "0.1.0"
15
+ # KeycloakRuby::Version.to_a # => [0, 1, 1]
16
+ # KeycloakRuby::Version.to_h # => { major: 0, minor: 1, patch: 1 }
17
+ # KeycloakRuby::Version.to_s # => "0.1.1"
14
18
  #
15
- # @example Checking version
16
- # KeycloakRuby::Version >= '0.1.0' # => true
17
- # Module for work with Version
19
+ # @example Version comparison
20
+ # KeycloakRuby::Version >= '0.1.0' # => true
21
+ # KeycloakRuby::Version >= '1.0.0' # => false
18
22
  module Version
19
- # Major version number (incompatible API changes)
20
- MAJOR = 0
21
- # Minor version number (backwards-compatible functionality)
22
- MINOR = 1
23
- # Patch version number (backwards-compatible bug fixes)
24
- PATCH = 1
25
- # Pre-release version (nil for stable releases)
26
- PRE = nil
27
-
28
- # Full version string
29
- VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".").freeze
30
-
31
- # Returns version components as an array
32
- # @return [Array<Integer, Integer, Integer, String|nil>]
23
+ # Returns the version components as an array of integers
24
+ # @return [Array<Integer>] the version components [major, minor, patch]
25
+ # @example
26
+ # KeycloakRuby::Version.to_a # => [0, 1, 1]
33
27
  def self.to_a
34
- [MAJOR, MINOR, PATCH, PRE]
28
+ VERSION.split(".").map(&:to_i)
35
29
  end
36
30
 
37
- # Returns version components as a hash
38
- # @return [Hash<Symbol, Integer|String|nil>]
31
+ # Returns the version components as a hash with symbols
32
+ # @return [Hash<Symbol, Integer>] the version components {major:, minor:, patch:}
33
+ # @example
34
+ # KeycloakRuby::Version.to_h # => { major: 0, minor: 1, patch: 1 }
39
35
  def self.to_h
40
- { major: MAJOR, minor: MINOR, patch: PATCH, pre: PRE }
36
+ { major: to_a[0], minor: to_a[1], patch: to_a[2] }
41
37
  end
42
38
 
43
- # Compares version with another version string
44
- # @param version_string [String] version to compare with (e.g., "1.2.3")
45
- # @return [Boolean]
39
+ # Compares the current version with another version string
40
+ # @param version_string [String] the version to compare with (e.g. "1.2.3")
41
+ # @return [Boolean] true if current version is greater or equal
42
+ # @example
43
+ # KeycloakRuby::Version >= '0.1.0' # => true
46
44
  def self.>=(version_string)
47
45
  Gem::Version.new(VERSION) >= Gem::Version.new(version_string)
48
46
  end
49
47
 
50
- # Returns the full version string
51
- # @return [String]
48
+ # Returns the version string
49
+ # @return [String] the version string
50
+ # @example
51
+ # KeycloakRuby::Version.to_s # => "0.1.1"
52
52
  def self.to_s
53
53
  VERSION
54
54
  end
55
55
  end
56
-
57
- # Returns the current gem version
58
- # @return [String]
59
- def self.version
60
- Version::VERSION
61
- end
62
56
  end
data/lib/keycloak_ruby.rb CHANGED
@@ -1,23 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # lib/keycloak_ruby.rb
3
4
  require "omniauth"
4
5
  require "omniauth_openid_connect"
5
6
  require "httparty"
6
7
  require "jwt"
8
+ require "zeitwerk"
9
+ require "omniauth/rails_csrf_protection/version"
10
+ require "omniauth/rails_csrf_protection/railtie" if defined?(Rails)
11
+ loader = Zeitwerk::Loader.for_gem
12
+ loader.ignore(
13
+ "#{__dir__}/generators",
14
+ "#{__dir__}/templates"
15
+ )
16
+ loader.setup
7
17
 
8
- # lib/keycloak_ruby.rb
9
18
  require "generators/keycloak_ruby/install_generator" if defined?(Rails)
10
- require "keycloak_ruby/authentication"
11
- require "keycloak_ruby/client"
12
- require "keycloak_ruby/config"
13
- require "keycloak_ruby/errors"
14
- require "keycloak_ruby/request_params"
15
- require "keycloak_ruby/request_performer"
16
- require "keycloak_ruby/response_validator"
17
- require "keycloak_ruby/token_refresher"
18
- require "keycloak_ruby/token_service"
19
- require "keycloak_ruby/user"
20
- require "keycloak_ruby/version"
21
19
 
22
20
  # Module for interacting with Keycloak
23
21
  module KeycloakRuby
@@ -27,15 +25,11 @@ module KeycloakRuby
27
25
  # Defaults to Rails.logger if available, or a standard Logger.
28
26
  #
29
27
  # @return [Logger]
28
+ # :reek:Attribute
30
29
  attr_writer :logger
31
30
 
32
31
  def logger
33
- @logger ||= if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger
34
- Rails.logger
35
- else
36
- require "logger"
37
- Logger.new($stdout).tap { |log| log.level = Logger::INFO }
38
- end
32
+ @logger ||= resolve_logger
39
33
  end
40
34
 
41
35
  # Returns the singleton configuration object. The configuration is
@@ -55,9 +49,32 @@ module KeycloakRuby
55
49
  yield config
56
50
  config.validate!
57
51
  end
52
+
53
+ private
54
+
55
+ def resolve_logger
56
+ if rails_defined? && rails_logger
57
+ rails_logger
58
+ else
59
+ default_logger
60
+ end
61
+ end
62
+
63
+ def rails_defined?
64
+ defined?(Rails)
65
+ end
66
+
67
+ def rails_logger
68
+ Rails.logger if rails_defined?
69
+ rescue NoMethodError
70
+ nil
71
+ end
72
+
73
+ def default_logger
74
+ require "logger"
75
+ Logger.new($stdout).tap { |log| log.level = Logger::INFO }
76
+ end
58
77
  end
59
- VERSION = Version::VERSION
60
- # Only load test helpers when in test environment
61
78
  # Load test helpers only in test environment
62
79
  if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test" || defined?(RSpec) || defined?(Minitest)
63
80
  require "keycloak_ruby/testing"