Skip to content

Commit 28546d8

Browse files
committed
Drop three blank? duplicates in favor of ActiveSupport Object#blank?
Configuration, UserProvisioner, and Presets::Zitadel each shipped their own private 'def blank?(value); value.nil? || value.to_s.strip.empty?; end' helper — same body, three copies. Rails >= 7.2 is a hard dependency of this gem, so ActiveSupport is always present in the host app; we only need to opt in to the core_ext at the gem entry point for unit specs that don't boot Rails and we get the standard Object#blank? behaviour everywhere else for free. Net -13 lines and a removal of subtle behaviour drift (the old helper treated false and 0 differently than the AS version would; nothing in the current call sites cared about either, but having only one definition means future call sites don't have to either).
1 parent 2a42b83 commit 28546d8

4 files changed

Lines changed: 6 additions & 19 deletions

File tree

lib/activeadmin-oidc.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# frozen_string_literal: true
22

33
require "logger"
4+
require "active_support/core_ext/object/blank"
45
require "activeadmin/oidc/version"
56

67
# `omniauth-rails_csrf_protection` registers a Railtie that replaces

lib/activeadmin/oidc/configuration.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,15 @@ def preset(name)
5656
end
5757

5858
def validate!
59-
raise ConfigurationError, "issuer is required" if blank?(issuer)
60-
raise ConfigurationError, "client_id is required" if blank?(client_id)
59+
raise ConfigurationError, "issuer is required" if issuer.blank?
60+
raise ConfigurationError, "client_id is required" if client_id.blank?
6161
raise ConfigurationError, "on_login is required" if on_login.nil?
6262
unless on_login.respond_to?(:call)
6363
raise ConfigurationError, "on_login must be callable (respond to #call)"
6464
end
6565

6666
true
6767
end
68-
69-
private
70-
71-
def blank?(value)
72-
value.nil? || value.to_s.strip.empty?
73-
end
7468
end
7569
end
7670
end

lib/activeadmin/oidc/presets/zitadel.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@ module Zitadel
88

99
def self.apply(config)
1010
config.scope = DEFAULT_SCOPE if config.scope == Configuration::DEFAULT_SCOPE
11-
config.pkce = true if blank?(config.client_secret) && config.instance_variable_get(:@pkce_override).nil?
11+
config.pkce = true if config.client_secret.blank? && config.instance_variable_get(:@pkce_override).nil?
1212
config
1313
end
14-
15-
def self.blank?(value)
16-
value.nil? || value.to_s.strip.empty?
17-
end
1814
end
1915
end
2016
end

lib/activeadmin/oidc/user_provisioner.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ def admin_user_class
5858
end
5959

6060
def validate_claims!
61-
if blank?(@claims["sub"])
61+
if @claims["sub"].blank?
6262
raise ProvisioningError, "OIDC id_token is missing a sub claim"
6363
end
6464

6565
claim_key = @config.identity_claim.to_s
66-
if blank?(@claims[claim_key])
66+
if @claims[claim_key].blank?
6767
raise ProvisioningError,
6868
"OIDC id_token is missing identity claim #{claim_key.inspect}"
6969
end
@@ -129,10 +129,6 @@ def invoke_on_login(admin_user)
129129
def denial_message
130130
@config.access_denied_message
131131
end
132-
133-
def blank?(value)
134-
value.nil? || value.to_s.strip.empty?
135-
end
136132
end
137133
end
138134
end

0 commit comments

Comments
 (0)