ruby-net-ldap
ruby-net-ldap copied to clipboard
Do we want to support method style attribute readers for Net::LDAP::Entry?
The current implementation of Net::LDAP::Entry#valid_argument?
requires an attribute to exist before you can use the method style accessors:
entry = Net::LDAP::Entry.new
entry.respond_to? :sn # false
entry.sn # raises NoMethodError
entry[:sn] = "foo"
entry.respond_to? :sn # true
entry.sn = "bar"
entry.sn # => "bar"
entry["sn"] # => "bar"
entry["Sn"] # => "bar"
This feels inconsistent and confusing. For 1.0, I'd like to clearly define how attributes can be accessed.
I looked into RFC 4517 for rules about valid attribute names, but didn't find any.
- Are attributes case sensitive?
- Can they have any characters in them?
- Do we want to support so many different styles of access?
cc @ruby-ldap/ruby-ldap-admins
Are attributes case sensitive? Can they have any characters in them?
Will follow up with links from the spec, but they are case-insensitive and they are UTF-8 encoded OCTET STRING
s (aka LDAPString
).
I will need to reread the implementation to know what role Net::LDAP::Entry#valid_argument?
has.
I've been viewing the method accessor as sugar and the []
lookup as preferred, standard, safe, "canonical" accessor. When the method accessor isn't as graceful, I don't mind as much since it's just a nicety. Thoughts?
And to be fair, that's only two styles of access, similar to OpenStruct.
I've been viewing the method accessor as sugar and the [] lookup as preferred, standard, safe, "canonical" accessor. When the method accessor isn't as graceful, I don't mind as much since it's just a nicety.
I'm fine with leaving the method accessors, but I'd like them to be consistent in behavior with their hash counterparts rather than depend on whether an attribute exists.
entry = Net::LDAP::Entry.new
# currently, if an attribute hasn't been assigned with the hash accessors,
# then we can't use the method accessors. I'd like this to return nil just like `entry[:sn]` would.
entry.sn # raise error
# alternatively, these should be equivalent
entry[:sn] == entry['sn'] == entry.sn
I'm kind of confused by what is being suggested here. If I specify in my search to only return these values: [:sn, :mail, :samaccountname], are you suggesting that if i call entry.memberof that it should just return nil?