Commit a6a764f7 authored by Michael Kozono's avatar Michael Kozono

Refactor initialize method for clarity

parent b3d61832
...@@ -34,24 +34,33 @@ module Gitlab ...@@ -34,24 +34,33 @@ module Gitlab
# so storing the dn as an escaped String and parsing parts as required # so storing the dn as an escaped String and parsing parts as required
# with a state machine seems sensible. # with a state machine seems sensible.
def initialize(*args) def initialize(*args)
buffer = StringIO.new if args.length > 1
initialize_array(args)
args.each_index do |index| else
buffer << "=" if index.odd? initialize_string(args[0])
buffer << "," if index.even? && index != 0 end
end
arg = args[index] def initialize_array(args)
buffer = StringIO.new
buffer << if index < args.length - 1 || index.odd? args.each_with_index do |arg, index|
self.class.escape(arg) if index.even? # key
else buffer << "," if index > 0
arg buffer << arg
end else # value
buffer << "="
buffer << self.class.escape(arg)
end
end end
@dn = buffer.string @dn = buffer.string
end end
def initialize_string(arg)
@dn = arg.to_s
end
## ##
# Parse a DN into key value pairs using ASN from # Parse a DN into key value pairs using ASN from
# http://tools.ietf.org/html/rfc2253 section 3. # 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