Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to select what attributes to return in Base find methods #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions active_directory.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require File.expand_path("../lib/active_directory/version", __FILE__)
require 'date'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need to require this?


Gem::Specification.new do |s|
s.name = "active_directory"
Expand Down
8 changes: 5 additions & 3 deletions lib/active_directory/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,11 @@ def self.find(*args)

options = {
:filter => (args[1].nil?) ? NIL_FILTER : args[1],
:in => (args[1].nil?) ? '' : ( args[1][:in] || '' )
:in => (args[1].nil?) ? '' : ( args[1][:in] || '' ),
:attributes => (args[1].nil?) ? [] : (args[1][:attributes] || [])
}
options[:filter].delete(:in)
options[:filter].delete(:attributes)

cached_results = find_cached_results(args[1])
return cached_results if cached_results or cached_results.nil?
Expand Down Expand Up @@ -323,7 +325,7 @@ def self.find_cached_results(filters)

def self.find_all(options)
results = []
ldap_objs = @@ldap.search(:filter => options[:filter], :base => options[:in]) || []
ldap_objs = @@ldap.search(:filter => options[:filter], :base => options[:in], :attributes => options[:attributes]) || []

ldap_objs.each do |entry|
ad_obj = new(entry)
Expand All @@ -335,7 +337,7 @@ def self.find_all(options)
end

def self.find_first(options)
ldap_result = @@ldap.search(:filter => options[:filter], :base => options[:in])
ldap_result = @@ldap.search(:filter => options[:filter], :base => options[:in], :attributes => options[:attributes])
return nil if ldap_result.empty?

ad_obj = new(ldap_result[0])
Expand Down