Class: Eco::API::Organization::People
- Inherits:
-
Language::Models::Collection
show all
- Defined in:
- lib/eco/api/organization/people.rb,
lib/eco/api/organization/people/similarity.rb,
lib/eco/api/organization/people/multiple_search_results.rb
Defined Under Namespace
Classes: MultipleSearchResults, Similarity
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.
15
16
17
18
19
20
|
# File 'lib/eco/api/organization/people.rb', line 15
def initialize(people = [], klass: Ecoportal::API::Internal::Person)
@klass = Ecoportal::API::Internal::Person unless klass == Ecoportal::API::V1::Person
super(people, klass: @klass)
@caches_init = false
end
|
Instance Method Details
#[](id_or_ext) ⇒ Object
32
33
34
|
# File 'lib/eco/api/organization/people.rb', line 32
def [](id_or_ext)
id(id_or_ext) || external_id(id_or_ext)
end
|
43
44
45
|
# File 'lib/eco/api/organization/people.rb', line 43
def contacts
details_present(true)
end
|
#email_id_maps ⇒ Object
185
186
187
|
# File 'lib/eco/api/organization/people.rb', line 185
def email_id_maps
users.group_by(:email).transform_values(&:id)
end
|
#exclude(object, strict: false) ⇒ Object
166
167
168
|
# File 'lib/eco/api/organization/people.rb', line 166
def exclude(object, strict: false)
exclude_people(into_a(object), strict: strict)
end
|
#exclude!(object, strict: false) ⇒ Object
170
171
172
|
# File 'lib/eco/api/organization/people.rb', line 170
def exclude!(object, strict: false)
self < exclude(object, strict: strict)
end
|
#exclude_people(list, strict: false) ⇒ Object
174
175
176
177
178
179
180
|
# File 'lib/eco/api/organization/people.rb', line 174
def exclude_people(list, strict: false)
list.map do |person|
find(person, strict: strict)
end.compact.then do |discarded|
newFrom to_a - discarded
end
end
|
#external_id(*args) ⇒ Object
28
29
30
|
# File 'lib/eco/api/organization/people.rb', line 28
def external_id(*args)
attr('external_id', *args).first
end
|
78
79
80
|
# File 'lib/eco/api/organization/people.rb', line 78
def filter_tags_all(tags)
attr('filter_tags', tags, default_modifier.all.insensitive)
end
|
74
75
76
|
# File 'lib/eco/api/organization/people.rb', line 74
def filter_tags_any(tags)
attr('filter_tags', tags, default_modifier.any.insensitive)
end
|
#find(object, strict: false) ⇒ Object
126
127
128
129
130
131
132
|
# File 'lib/eco/api/organization/people.rb', line 126
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
193
194
195
196
197
198
199
|
# File 'lib/eco/api/organization/people.rb', line 193
def group_by_schema
to_h do |person|
next unless (details = person.details)
details.schema_id
end
end
|
#group_by_supervisor ⇒ Object
189
190
191
|
# File 'lib/eco/api/organization/people.rb', line 189
def group_by_supervisor
to_h(:supervisor_id)
end
|
#id(*args) ⇒ Object
24
25
26
|
# File 'lib/eco/api/organization/people.rb', line 24
def id(*args)
attr('id', *args).first
end
|
#merge(data, strict: false, uniq: true) ⇒ Object
160
161
162
163
164
|
# File 'lib/eco/api/organization/people.rb', line 160
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
69
70
71
72
|
# File 'lib/eco/api/organization/people.rb', line 69
def missing_supervisors_ids
sup_ids = supervisor_ids
sup_ids - (sup_ids & ids)
end
|
#newFrom(data) ⇒ Object
rubocop:disable Naming/MethodName
141
142
143
|
# File 'lib/eco/api/organization/people.rb', line 141
def newFrom(data) self.class.new(data, klass: @klass)
end
|
#non_users ⇒ Object
47
48
49
|
# File 'lib/eco/api/organization/people.rb', line 47
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.
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/eco/api/organization/people.rb', line 112
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
86
87
88
|
# File 'lib/eco/api/organization/people.rb', line 86
def policy_group_ids_all(ids)
attr('policy_group_ids', ids, default_modifier.all.insensitive)
end
|
#policy_group_ids_any(ids) ⇒ Object
82
83
84
|
# File 'lib/eco/api/organization/people.rb', line 82
def policy_group_ids_any(ids)
attr('policy_group_ids', ids, default_modifier.any.insensitive)
end
|
#supervisors ⇒ Object
60
61
62
63
64
65
66
67
|
# File 'lib/eco/api/organization/people.rb', line 60
def supervisors
sup_ids = ids & supervisor_ids
sup_ids.map do |id|
person(id: id, strict: true)
end.then do |supervisors|
newFrom supervisors
end
end
|
#to_h(attr = 'id') ⇒ Object
201
202
203
|
# File 'lib/eco/api/organization/people.rb', line 201
def to_h(attr = 'id')
super(attr || 'id')
end
|
137
138
139
|
# File 'lib/eco/api/organization/people.rb', line 137
def to_json(...)
to_a.to_json(...)
end
|
#uniq(strict: false, include_unsearchable: false) ⇒ Object
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/eco/api/organization/people.rb', line 145
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.then do |found|
found += unsearchable if include_unsearchable
newFrom found
end
end
|
#updated_or_created ⇒ Object
Returns the people that are being or have been updated and/or created.
52
53
54
55
56
57
58
|
# File 'lib/eco/api/organization/people.rb', line 52
def updated_or_created
select do |person|
!person.as_update(:total).empty?
end.then do |persons|
newFrom persons
end
end
|
39
40
41
|
# File 'lib/eco/api/organization/people.rb', line 39
def users
account_present(true)
end
|