Class: Eco::API::Organization::People
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
|
# 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
31
32
33
|
# File 'lib/eco/api/organization/people.rb', line 31
def [](id_or_ext)
id(id_or_ext) || external_id(id_or_ext)
end
|
42
43
44
|
# File 'lib/eco/api/organization/people.rb', line 42
def contacts
details_present(true)
end
|
#email_id_maps ⇒ Object
183
184
185
|
# File 'lib/eco/api/organization/people.rb', line 183
def email_id_maps
users.group_by(:email).transform_values(&:id)
end
|
#exclude(object, strict: false) ⇒ Object
164
165
166
|
# File 'lib/eco/api/organization/people.rb', line 164
def exclude(object, strict: false)
exclude_people(into_a(object), strict: strict)
end
|
#exclude!(object, strict: false) ⇒ Object
168
169
170
|
# File 'lib/eco/api/organization/people.rb', line 168
def exclude!(object, strict: false)
self < exclude(object, strict: strict)
end
|
#exclude_people(list, strict: false) ⇒ Object
172
173
174
175
176
177
178
|
# File 'lib/eco/api/organization/people.rb', line 172
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
27
28
29
|
# File 'lib/eco/api/organization/people.rb', line 27
def external_id(*args)
attr('external_id', *args).first
end
|
77
78
79
|
# File 'lib/eco/api/organization/people.rb', line 77
def filter_tags_all(tags)
attr('filter_tags', tags, default_modifier.all.insensitive)
end
|
73
74
75
|
# File 'lib/eco/api/organization/people.rb', line 73
def filter_tags_any(tags)
attr('filter_tags', tags, default_modifier.any.insensitive)
end
|
#find(object, strict: false) ⇒ Object
125
126
127
128
129
130
|
# File 'lib/eco/api/organization/people.rb', line 125
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
191
192
193
194
195
196
197
|
# File 'lib/eco/api/organization/people.rb', line 191
def group_by_schema
to_h do |person|
next unless (details = person.details)
details.schema_id
end
end
|
#group_by_supervisor ⇒ Object
187
188
189
|
# File 'lib/eco/api/organization/people.rb', line 187
def group_by_supervisor
to_h(:supervisor_id)
end
|
#id(*args) ⇒ Object
23
24
25
|
# File 'lib/eco/api/organization/people.rb', line 23
def id(*args)
attr('id', *args).first
end
|
#merge(data, strict: false, uniq: true) ⇒ Object
158
159
160
161
162
|
# File 'lib/eco/api/organization/people.rb', line 158
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
68
69
70
71
|
# File 'lib/eco/api/organization/people.rb', line 68
def missing_supervisors_ids
sup_ids = supervisor_ids
sup_ids - (sup_ids & ids)
end
|
#newFrom(data) ⇒ Object
rubocop:disable Naming/MethodName
139
140
141
|
# File 'lib/eco/api/organization/people.rb', line 139
def newFrom(data) self.class.new(data, klass: @klass)
end
|
#non_users ⇒ Object
46
47
48
|
# File 'lib/eco/api/organization/people.rb', line 46
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.
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/eco/api/organization/people.rb', line 111
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
85
86
87
|
# File 'lib/eco/api/organization/people.rb', line 85
def policy_group_ids_all(ids)
attr('policy_group_ids', ids, default_modifier.all.insensitive)
end
|
#policy_group_ids_any(ids) ⇒ Object
81
82
83
|
# File 'lib/eco/api/organization/people.rb', line 81
def policy_group_ids_any(ids)
attr('policy_group_ids', ids, default_modifier.any.insensitive)
end
|
#similarity ⇒ Object
205
206
207
|
# File 'lib/eco/api/organization/people.rb', line 205
def similarity
Eco::API::Organization::People::Similarity.new(to_a)
end
|
#supervisors ⇒ Object
59
60
61
62
63
64
65
66
|
# File 'lib/eco/api/organization/people.rb', line 59
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
199
200
201
|
# File 'lib/eco/api/organization/people.rb', line 199
def to_h(attr = 'id')
super(attr || 'id')
end
|
135
136
137
|
# File 'lib/eco/api/organization/people.rb', line 135
def to_json
to_a.to_json
end
|
#uniq(strict: false, include_unsearchable: false) ⇒ Object
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/eco/api/organization/people.rb', line 143
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.
51
52
53
54
55
56
57
|
# File 'lib/eco/api/organization/people.rb', line 51
def updated_or_created
select do |person|
!person.as_update(:total).empty?
end.then do |persons|
newFrom persons
end
end
|
38
39
40
|
# File 'lib/eco/api/organization/people.rb', line 38
def users
account_present(true)
end
|