Class: UcbRails::LdapPerson::TestFinder

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

Constant Summary collapse

PersonNotFound =
Class.new(StandardError)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.entriesObject



28
29
30
31
32
33
34
35
# File 'app/models/ucb_rails/ldap_person/test_finder.rb', line 28

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

.new_entry(uid, calnet_id, fn, ln, email, phone, depts) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/ucb_rails/ldap_person/test_finder.rb', line 37

def self.new_entry(uid, calnet_id, fn, ln, email, phone, depts)
  ::UcbRails::LdapPerson::Entry.new(
    :uid => uid,
    :calnet_id => calnet_id,
    :first_name => fn,
    :last_name => ln,
    :email => email,
    :phone => phone,
    :departments => depts
  )
end

Instance Method Details

#entry_matches_attributes(entry, attributes) ⇒ Object



21
22
23
24
25
26
# File 'app/models/ucb_rails/ldap_person/test_finder.rb', line 21

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

#find_by_attributes(attributes) ⇒ Object



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

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/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/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/ldap_person/test_finder.rb', line 9

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