Class: ActiveDirectory::Container
- Inherits:
-
Object
- Object
- ActiveDirectory::Container
- Defined in:
- lib/active_directory/container.rb
Overview
The ActiveDirectory::Container class represents a more malleable way of dealing with LDAP Distinguished Names (dn), like “cn=UserName,ou=Users,dc=example,dc=org”.
The following two representations of the above dn are identical:
dn = "cn=UserName,ou=Users,dc=example,dc=org"
dn = ActiveDirectory::Container.dc('org').dc('example').ou('Users').cn('UserName').to_s
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.cn(name) ⇒ Object
Creates a starting CN (Canonical Name) dn part.
-
.dc(name) ⇒ Object
Creates a starting DC (Domain Component) dn part.
-
.ou(name) ⇒ Object
Creates a starting OU (Organizational Unit) dn part.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#cn(name) ⇒ Object
Appends a CN (Canonical Name) dn part to another Container.
-
#dc(name) ⇒ Object
Appends a DC (Domain Component) dn part to another Container.
-
#initialize(type, name, node = nil) ⇒ Container
constructor
:nodoc:.
-
#ou(name) ⇒ Object
Appends an OU (Organizational Unit) dn part to another Container.
-
#to_s ⇒ Object
Converts the Container object to its String representation.
Constructor Details
#initialize(type, name, node = nil) ⇒ Container
:nodoc:
17 18 19 20 21 |
# File 'lib/active_directory/container.rb', line 17 def initialize(type, name, node = nil) #:nodoc: @type = type @name = name @node = node end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/active_directory/container.rb', line 14 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
15 16 17 |
# File 'lib/active_directory/container.rb', line 15 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/active_directory/container.rb', line 13 def type @type end |
Class Method Details
.cn(name) ⇒ Object
Creates a starting CN (Canonical Name) dn part.
# cn_part = "cn=CanonicalName"
cn_part = ActiveDirectory::Container.cn('CanonicalName').to_s
49 50 51 |
# File 'lib/active_directory/container.rb', line 49 def self.cn(name) new(:cn, name, nil) end |
.dc(name) ⇒ Object
Creates a starting DC (Domain Component) dn part.
# dc_part = "dc=net"
dc_part = ActiveDirectory::Container.dc('net').to_s
39 40 41 |
# File 'lib/active_directory/container.rb', line 39 def self.dc(name) new(:dc, name, nil) end |
.ou(name) ⇒ Object
Creates a starting OU (Organizational Unit) dn part.
# ou_part = "ou=OrganizationalUnit"
ou_part = ActiveDirectory::Container.ou('OrganizationalUnit').to_s
29 30 31 |
# File 'lib/active_directory/container.rb', line 29 def self.ou(name) new(:ou, name, nil) end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
90 91 92 |
# File 'lib/active_directory/container.rb', line 90 def ==(other) #:nodoc: to_s.downcase == other.to_s.downcase end |
#cn(name) ⇒ Object
Appends a CN (Canonical Name) dn part to another Container.
# user = "cn=UID,ou=Users"
user = ActiveDirectory::Container.ou("Users").cn("UID")
79 80 81 |
# File 'lib/active_directory/container.rb', line 79 def cn(name) self.class.new(:cn, name, self) end |
#dc(name) ⇒ Object
Appends a DC (Domain Component) dn part to another Container.
# base = "dc=example,dc=net"
base = ActiveDirectory::Container.dc("net").dc("example").to_s
69 70 71 |
# File 'lib/active_directory/container.rb', line 69 def dc(name) self.class.new(:dc, name, self) end |
#ou(name) ⇒ Object
Appends an OU (Organizational Unit) dn part to another Container.
# ou = "ou=InfoTech,dc=net"
ou = ActiveDirectory::Container.dc("net").ou("InfoTech").to_s
59 60 61 |
# File 'lib/active_directory/container.rb', line 59 def ou(name) self.class.new(:ou, name, self) end |
#to_s ⇒ Object
Converts the Container object to its String representation.
86 87 88 |
# File 'lib/active_directory/container.rb', line 86 def to_s @node ? "#{@type}=#{name},#{@node.to_s}" : "#{@type}=#{name}" end |