ruby-net-ldap icon indicating copy to clipboard operation
ruby-net-ldap copied to clipboard

Do we want to support method style attribute readers for Net::LDAP::Entry?

Open jch opened this issue 9 years ago • 3 comments

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

jch avatar Oct 09 '14 18:10 jch

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 STRINGs (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.

mtodd avatar Oct 11 '14 05:10 mtodd

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

jch avatar Oct 11 '14 19:10 jch

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?

yairgo avatar Feb 26 '16 18:02 yairgo