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:
40 41 42 43 44 |
# File 'lib/active_directory/container.rb', line 40 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.
37 38 39 |
# File 'lib/active_directory/container.rb', line 37 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
38 39 40 |
# File 'lib/active_directory/container.rb', line 38 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
36 37 38 |
# File 'lib/active_directory/container.rb', line 36 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
72 73 74 |
# File 'lib/active_directory/container.rb', line 72 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
62 63 64 |
# File 'lib/active_directory/container.rb', line 62 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
52 53 54 |
# File 'lib/active_directory/container.rb', line 52 def self.ou(name) new(:ou, name, nil) end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
113 114 115 |
# File 'lib/active_directory/container.rb', line 113 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")
102 103 104 |
# File 'lib/active_directory/container.rb', line 102 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
92 93 94 |
# File 'lib/active_directory/container.rb', line 92 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
82 83 84 |
# File 'lib/active_directory/container.rb', line 82 def ou(name) self.class.new(:ou, name, self) end |
#to_s ⇒ Object
Converts the Container object to its String representation.
109 110 111 |
# File 'lib/active_directory/container.rb', line 109 def to_s @node ? "#{@type}=#{name},#{@node.to_s}" : "#{@type}=#{name}" end |