From 2fe7e501f369a6ea775567b10f1e881b13b5fa37 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 6 Apr 2017 10:46:31 +0200 Subject: [PATCH] Added method to get a duplicate of the internal Hash to avoid each loops to get a Hash. --- lib/net/ldap/entry.rb | 7 +++++++ test/test_entry.rb | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/net/ldap/entry.rb b/lib/net/ldap/entry.rb index 10965c7c..418512f0 100644 --- a/lib/net/ldap/entry.rb +++ b/lib/net/ldap/entry.rb @@ -133,6 +133,13 @@ def attribute_names @myhash.keys end + ## + # Creates a duplicate of the internal Hash containing the attributes + # of the entry. + def to_h + @myhash.dup + end + ## # Accesses each of the attributes present in the Entry. # diff --git a/test/test_entry.rb b/test/test_entry.rb index e2184747..6667eab9 100644 --- a/test/test_entry.rb +++ b/test/test_entry.rb @@ -39,6 +39,21 @@ def test_case_insensitive_attribute_names assert_equal ['Jensen'], @entry['Sn'] assert_equal ['Jensen'], @entry['SN'] end + + def test_to_h + @entry['sn'] = 'Jensen' + expected = { + dn: ['cn=Barbara,o=corp'], + sn: ['Jensen'], + } + duplicate = @entry.to_h + assert_equal expected, duplicate + + # check that changing the duplicate + # does not affect the internal state + duplicate.delete(:sn) + assert_not_equal duplicate, @entry.to_h + end end class TestEntryLDIF < Test::Unit::TestCase pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy