summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Kozono <mkozono@gmail.com>2017-10-02 14:57:57 -0700
committerMichael Kozono <mkozono@gmail.com>2017-10-07 10:28:13 -0700
commita6a764f73debb41005fbfe7e902c9f51e2bbcff1 (patch)
treea88b62f0671ad8ec4910925866ec4b659c8c5603
parentb3d61832c37b037f95dad619dd8c0680b6513818 (diff)
downloadgitlab-ce-a6a764f73debb41005fbfe7e902c9f51e2bbcff1.tar.gz
Refactor initialize method for clarity
-rw-r--r--lib/gitlab/ldap/dn.rb31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/gitlab/ldap/dn.rb b/lib/gitlab/ldap/dn.rb
index 3766893ff6d..060f61d1a10 100644
--- a/lib/gitlab/ldap/dn.rb
+++ b/lib/gitlab/ldap/dn.rb
@@ -34,24 +34,33 @@ module Gitlab
# so storing the dn as an escaped String and parsing parts as required
# with a state machine seems sensible.
def initialize(*args)
- buffer = StringIO.new
-
- args.each_index do |index|
- buffer << "=" if index.odd?
- buffer << "," if index.even? && index != 0
+ if args.length > 1
+ initialize_array(args)
+ else
+ initialize_string(args[0])
+ end
+ end
- arg = args[index]
+ def initialize_array(args)
+ buffer = StringIO.new
- buffer << if index < args.length - 1 || index.odd?
- self.class.escape(arg)
- else
- arg
- end
+ args.each_with_index do |arg, index|
+ if index.even? # key
+ buffer << "," if index > 0
+ buffer << arg
+ else # value
+ buffer << "="
+ buffer << self.class.escape(arg)
+ end
end
@dn = buffer.string
end
+ def initialize_string(arg)
+ @dn = arg.to_s
+ end
+
##
# Parse a DN into key value pairs using ASN from
# http://tools.ietf.org/html/rfc2253 section 3.