Commit a6a764f7 authored by Michael Kozono's avatar Michael Kozono

Refactor initialize method for clarity

parent b3d61832
......@@ -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
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment