Class: Eco::API::Organization::People
Defined Under Namespace
Classes: MultipleSearchResults
Constant Summary
Language::Models::Collection::BASIC_METHODS, Language::Models::Collection::EXTENDED_METHODS
Main identifier helpers
collapse
Basic Collection Methods
collapse
Groupping methods
collapse
Instance Method Summary
collapse
#<, #<<, #attr, #attr?, attr_collection, attr_presence, #attrs, attrs_create_method, #contains, #delete!, #each, #empty, #empty?, #group_by, #length, #new, #present, #present_all?, #present_some?, #remove, #to_c, #unique_attrs, #update
Constructor Details
#initialize(people = [], klass: Ecoportal::API::Internal::Person) ⇒ People
Returns a new instance of People.
Instance Method Details
#[](id_or_ext) ⇒ Object
64
65
66
|
# File 'lib/eco/api/organization/people.rb', line 64
def [](id_or_ext)
id(id_or_ext) || external_id(id_or_ext)
end
|
75
76
77
|
# File 'lib/eco/api/organization/people.rb', line 75
def contacts
details_present(true)
end
|
#email_id_maps ⇒ Object
205
206
207
|
# File 'lib/eco/api/organization/people.rb', line 205
def email_id_maps
users.group_by(:email).transform_values { |person| person.id }
end
|
#exclude(object, strict: false) ⇒ Object
186
187
188
|
# File 'lib/eco/api/organization/people.rb', line 186
def exclude(object, strict: false)
exclude_people(into_a(object), strict: strict)
end
|
#exclude!(object, strict: false) ⇒ Object
190
191
192
|
# File 'lib/eco/api/organization/people.rb', line 190
def exclude!(object, strict: false)
self < exclude(object, strict: strict)
end
|
#exclude_people(list, strict: false) ⇒ Object
194
195
196
197
198
199
200
|
# File 'lib/eco/api/organization/people.rb', line 194
def exclude_people(list, strict: false)
list.map do |person|
find(person, strict: strict)
end.compact.yield_self do |discarded|
newFrom to_a - discarded
end
end
|
#external_id(*args) ⇒ Object
60
61
62
|
# File 'lib/eco/api/organization/people.rb', line 60
def external_id(*args)
attr('external_id', *args).first
end
|
101
102
103
|
# File 'lib/eco/api/organization/people.rb', line 101
def filter_tags_all(tags)
attr("filter_tags", tags, default_modifier.all.insensitive)
end
|
97
98
99
|
# File 'lib/eco/api/organization/people.rb', line 97
def filter_tags_any(tags)
attr("filter_tags", tags, default_modifier.any.insensitive)
end
|
#find(object, strict: false) ⇒ Object
148
149
150
151
152
153
|
# File 'lib/eco/api/organization/people.rb', line 148
def find(object, strict: false)
id = attr_value(object, "id")
external_id = attr_value(object, "external_id")
email = attr_value(object, "email")
person(id: id, external_id: external_id, email: email, strict: strict)
end
|
#group_by_schema ⇒ Object
213
214
215
216
217
|
# File 'lib/eco/api/organization/people.rb', line 213
def group_by_schema
to_h do |person|
person.details && person.details.schema_id
end
end
|
#group_by_supervisor ⇒ Object
209
210
211
|
# File 'lib/eco/api/organization/people.rb', line 209
def group_by_supervisor
to_h(:supervisor_id)
end
|
#id(*args) ⇒ Object
56
57
58
|
# File 'lib/eco/api/organization/people.rb', line 56
def id(*args)
attr('id', *args).first
end
|
#merge(data, strict: false, uniq: true) ⇒ Object
180
181
182
183
184
|
# File 'lib/eco/api/organization/people.rb', line 180
def merge(data, strict: false, uniq: true)
list = uniq ? exclude_people(data, strict: strict).to_a : to_a
data = data.to_a unless data.is_a?(Array)
newFrom list + data
end
|
#missing_supervisors_ids ⇒ Object
92
93
94
95
|
# File 'lib/eco/api/organization/people.rb', line 92
def missing_supervisors_ids
sup_ids = self.supervisor_ids
sup_ids - (sup_ids & self.ids)
end
|
#newFrom(data) ⇒ Object
162
163
164
|
# File 'lib/eco/api/organization/people.rb', line 162
def newFrom(data)
self.class.new(data, klass: @klass)
end
|
#non_users ⇒ Object
79
80
81
|
# File 'lib/eco/api/organization/people.rb', line 79
def non_users
account_present(false)
end
|
#person(id: nil, external_id: nil, email: nil, strict: false) ⇒ Person?
Note:
This is how the search function actually works:
- if eP
id
is given, returns the person (if found), otherwise...
- if
external_id
is given, returns the person (if found), otherwise...
- if
strict
is false
and email
is given:
- if there is only 1 person with that email, returns that person, otherwise...
- if found but, there are many candidates, it raises MultipleSearchResults error
- if person
external_id
matches email
, returns that person
It searches a person using the parameters given.
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/eco/api/organization/people.rb', line 134
def person(id: nil, external_id: nil, email: nil, strict: false)
init_caches
ext_id = !external_id.to_s.strip.empty? && external_id.strip
email = !email.to_s.strip.empty? && email.downcase.strip
pers = nil
pers ||= @by_id[id]&.first
pers ||= @by_external_id[ext_id]&.first
pers ||= person_by_email(email) unless strict && ext_id
pers
end
|
#policy_group_ids_all(ids) ⇒ Object
109
110
111
|
# File 'lib/eco/api/organization/people.rb', line 109
def policy_group_ids_all(ids)
attr("policy_group_ids", tags, default_modifier.all.insensitive)
end
|
#policy_group_ids_any(ids) ⇒ Object
105
106
107
|
# File 'lib/eco/api/organization/people.rb', line 105
def policy_group_ids_any(ids)
attr("policy_group_ids", tags, default_modifier.any.insensitive)
end
|
#supervisors ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/eco/api/organization/people.rb', line 83
def supervisors
sup_ids = self.ids & self.supervisor_ids
sup_ids.map do |id|
person(id: id, strict: true)
end.yield_self do |supervisors|
newFrom supervisors
end
end
|
#to_h(attr = "id") ⇒ Object
219
220
221
|
# File 'lib/eco/api/organization/people.rb', line 219
def to_h(attr = "id")
super(attr || "id")
end
|
#to_json ⇒ Object
158
159
160
|
# File 'lib/eco/api/organization/people.rb', line 158
def to_json
to_a.to_json
end
|
#uniq(strict: false, include_unsearchable: false) ⇒ Object
166
167
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/eco/api/organization/people.rb', line 166
def uniq(strict: false, include_unsearchable: false)
unsearchable = []
to_a.each_with_object([]) do |person, people|
if found = find(person, strict: strict)
people << found
else
unsearchable << person
end
end.yield_self do |found|
found += unsearchable if include_unsearchable
newFrom found
end
end
|
#users ⇒ Object
71
72
73
|
# File 'lib/eco/api/organization/people.rb', line 71
def users
account_present(true)
end
|