Class: UcbRailsUser::LdapPerson::TestFinder

Inherits:
Object
  • Object
show all
Defined in:
app/models/ucb_rails_user/ldap_person/test_finder.rb

Constant Summary collapse

PersonNotFound =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.entriesObject



32
33
34
35
36
37
38
39
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 32

def self.entries
  [
    new_entry("1", 'art', "Art", "Andrews", "[email protected]", "999-999-0001", "Dept 1", "011"),
    new_entry("2", 'beth', "Beth", "Brown", "[email protected]", "999-999-0002", "Dept 2", "012"),
    new_entry("61065", 'runner', "Steven", "Hansen", "[email protected]", "999-999-9998", "EAS", "0161065"),
    new_entry("191501", 'stevedowney', "Steve", "Downey", "[email protected]", "999-999-9999", "EAS", "01191501"),
  ]
end

.new_entry(uid, calnet_id, fn, ln, email, phone, depts, employee_id = nil, affiliate_id = nil) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 41

def self.new_entry(uid, calnet_id, fn, ln, email, phone, depts, employee_id = nil, affiliate_id = nil)
  ::UcbRailsUser::LdapPerson::Entry.new(
    :uid => uid,
    :calnet_id => calnet_id,
    :first_name => fn,
    :last_name => ln,
    :email => email,
    :phone => phone,
    :departments => depts,
    :employee_id => employee_id,
    :affiliate_id => affiliate_id,
    :inactive => false
  )
end

Instance Method Details

#entry_matches_attributes(entry, attributes) ⇒ Object



25
26
27
28
29
30
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 25

def entry_matches_attributes(entry, attributes)
  attributes.keys.all? do |key|
    value = attributes[key].to_s.downcase
    value.blank? || (entry.respond_to?(key) && entry.send(key).to_s.downcase.include?(value))
  end
end

#find_by_affiliate_id(affiliate_id) ⇒ Object



17
18
19
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 17

def find_by_affiliate_id(affiliate_id)
  find_by_attributes("affiliate_id" => affiliate_id)
end

#find_by_attributes(attributes) ⇒ Object



21
22
23
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 21

def find_by_attributes(attributes)
  self.class.entries.select { |entry| entry_matches_attributes(entry, attributes) }
end

#find_by_first_last(first_name, last_name, options = {}) ⇒ Object



13
14
15
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 13

def find_by_first_last(first_name, last_name, options={})
  find_by_attributes(:first_name => first_name, :last_name => last_name)
end

#find_by_uid(uid) ⇒ Object



5
6
7
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 5

def find_by_uid(uid)
  uid.presence and find_by_attributes(:uid => uid.to_s).first
end

#find_by_uid!(uid) ⇒ Object



9
10
11
# File 'app/models/ucb_rails_user/ldap_person/test_finder.rb', line 9

def find_by_uid!(uid)
  find_by_uid(uid) || raise(PersonNotFound, "uid=#{uid.inspect}")
end