Class: DN
Overview
rubocop:disable ClassLength Accepts various DN strings and returns a DN object
Instance Attribute Summary collapse
-
#c ⇒ Object
Returns the value of attribute c.
-
#cn ⇒ Object
Returns the value of attribute cn.
-
#dc ⇒ Object
Returns the value of attribute dc.
-
#delimiter ⇒ Object
Returns the value of attribute delimiter.
-
#dn_string ⇒ Object
Returns the value of attribute dn_string.
-
#l ⇒ Object
Returns the value of attribute l.
-
#o ⇒ Object
Returns the value of attribute o.
-
#original_dn ⇒ Object
Returns the value of attribute original_dn.
-
#ou ⇒ Object
Returns the value of attribute ou.
-
#st ⇒ Object
Returns the value of attribute st.
-
#street ⇒ Object
Returns the value of attribute street.
-
#string_order ⇒ Object
Returns the value of attribute string_order.
-
#transformation ⇒ Object
Returns the value of attribute transformation.
-
#uid ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ DN
constructor
Initialize the instance.
-
#logger ⇒ Object
logger method to return Rails logger if defined, else logging logger.
-
#split_by_delimiter ⇒ Object
Split passed DN by identified delimiter.
-
#to_s ⇒ Object
Convert DN object into a string (order follows RFC4514 LDAP specifications).
Constructor Details
#initialize(opts = {}) ⇒ DN
Initialize the instance
NOTE: opts[transformation] defaults to "upcase"; use "to_s" for no change. NOTE: opts[:string_order] is a last resort config, defaults to RFC4514 spec.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dnc/dn.rb', line 27 def initialize(opts = {}) @dn_string = opts[:dn_string] raise 'dnc: dn_string parameter is **required**' if dn_string.nil? @original_dn = dn_string @logger = opts[:logger] || logger @transformation = opts[:transformation] || 'upcase' @string_order = opts[:string_order] || %w(cn l st o ou c street dc uid) @delimiter = opts[:delimiter] || identify_delimiter format_dn end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object (private)
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/dnc/dn.rb', line 149 def method_missing(method_name) # Catch methods that end with _string method_match = method_name.to_s.match(/(.+)_string\z/) unless method_match.blank? method = method_match[1] method_class = send(method.to_sym).class return send(:dynamic_strings, method.to_s, method_class) end super end |
Instance Attribute Details
#cn ⇒ Object
Returns the value of attribute cn.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def cn @cn end |
#dc ⇒ Object
Returns the value of attribute dc.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def dc @dc end |
#delimiter ⇒ Object
Returns the value of attribute delimiter.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def delimiter @delimiter end |
#dn_string ⇒ Object
Returns the value of attribute dn_string.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def dn_string @dn_string end |
#original_dn ⇒ Object
Returns the value of attribute original_dn.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def original_dn @original_dn end |
#ou ⇒ Object
Returns the value of attribute ou.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def ou @ou end |
#st ⇒ Object
Returns the value of attribute st.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def st @st end |
#street ⇒ Object
Returns the value of attribute street.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def street @street end |
#string_order ⇒ Object
Returns the value of attribute string_order.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def string_order @string_order end |
#transformation ⇒ Object
Returns the value of attribute transformation.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def transformation @transformation end |
#uid ⇒ Object
Returns the value of attribute uid.
13 14 15 |
# File 'lib/dnc/dn.rb', line 13 def uid @uid end |
Instance Method Details
#logger ⇒ Object
logger method to return Rails logger if defined, else logging logger
39 40 41 42 43 44 45 |
# File 'lib/dnc/dn.rb', line 39 def logger unless defined? @logger logger = Logging.logger[self] @logger = Kernel.const_defined?('Rails') ? Rails.logger : logger end @logger end |
#split_by_delimiter ⇒ Object
Split passed DN by identified delimiter
61 62 63 |
# File 'lib/dnc/dn.rb', line 61 def split_by_delimiter dn_string.split(delimiter).reject(&:empty?) end |
#to_s ⇒ Object
Convert DN object into a string (order follows RFC4514 LDAP specifications)
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dnc/dn.rb', line 48 def to_s return_string = '' @string_order.each do |string_name| unless send(string_name.to_sym).blank? return_string += ',' unless return_string.empty? return_string += send("#{string_name}_string".to_sym) end end return_string end |