Class: Eco::API::Common::People::Entries
Overview
Class meant to offer a collection of entries, normally used to get parsed input data.
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
#identify_cyclic_chains, #print_tree, #sort_by_supervisors, #supervisors_tree, #tree_to_str
#<, #<<, #attr, #attr?, attr_collection, attr_presence, #attrs, attrs_create_method, #contains, #delete!, #empty, #empty?, #group_by, #length, #merge, #new, #newFrom, #present, #present_all?, #present_some?, #remove, #to_c, #unique_attrs, #update
Constructor Details
#initialize(data = [], klass:, factory:) ⇒ Entries
Returns a new instance of Entries.
51
52
53
54
|
# File 'lib/eco/api/common/people/entries.rb', line 51
def initialize(data = [], klass:, factory:)
super(data, klass: klass, factory: factory)
@caches_init = false
end
|
Instance Method Details
#[](id_or_ext) ⇒ Object
66
67
68
|
# File 'lib/eco/api/common/people/entries.rb', line 66
def [](id_or_ext)
id(id_or_ext) || external_id(id_or_ext)
end
|
#each(&block) ⇒ Object
Override each
to make it work with supervisor hiearchy
136
137
138
139
140
|
# File 'lib/eco/api/common/people/entries.rb', line 136
def each(&block)
return to_enum(:each) unless block
@array_supers = sort_by_supervisors(@items) unless @caches_init
@array_supers.each(&block)
end
|
#email_id_maps ⇒ Object
169
170
171
|
# File 'lib/eco/api/common/people/entries.rb', line 169
def email_id_maps
email_present.group_by(:email).transform_values { |person| person.id }
end
|
#entry(id: nil, external_id: nil, email: nil, strict: false) ⇒ Entry?
Note:
This is how the search function actually works:
- if eP
id
is given, returns the entry (if found), otherwise...
- if
external_id
is given, returns the entry (if found), otherwise...
- if
strict
is false
and email
is given:
- if there is only 1 entry with that email, returns that entry, otherwise...
- if found but, there are many candidate entries, it raises MultipleSearchResults error
- if entry
external_id
matches email
, returns that entry
Search function to find an entry
based on one of different options
It searches an entry using the parameters given.
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/eco/api/common/people/entries.rb', line 110
def entry(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
e = nil
e ||= @by_id[id]&.first
e ||= @by_external_id[ext_id]&.first
e ||= entry_by_email(email) unless strict && ext_id
e
end
|
#exclude(object) ⇒ Object
142
143
144
|
# File 'lib/eco/api/common/people/entries.rb', line 142
def exclude(object)
exclude_people(into_a(object))
end
|
#exclude_people(list) ⇒ Object
146
147
148
149
150
151
|
# File 'lib/eco/api/common/people/entries.rb', line 146
def exclude_people(list)
discarded = list.map do |person|
find(person)
end.compact
newFrom to_a - discarded
end
|
#export(filename) ⇒ Object
TODO: it should rather use the the people-to-csv case somehow
Helper to dump the entries into a CSV
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/eco/api/common/people/entries.rb', line 156
def export(filename)
CSV.open(filename, "w") do |csv|
entry = self.first
= entry.internal_entry.keys
csv <<
self.each do |entry|
csv << entry.internal_entry.values
end
end
end
|
#external_id(*args) ⇒ Object
62
63
64
|
# File 'lib/eco/api/common/people/entries.rb', line 62
def external_id(*args)
attr('external_id', *args).first
end
|
77
78
79
|
# File 'lib/eco/api/common/people/entries.rb', line 77
def filter_tags_all(tags)
attr("filter_tags", tags, default_modifier.all.insensitive)
end
|
73
74
75
|
# File 'lib/eco/api/common/people/entries.rb', line 73
def filter_tags_any(tags)
attr("filter_tags", tags, default_modifier.any.insensitive)
end
|
#find(object, strict: false) ⇒ Object
Search function to find an entry
based on one of different options
see Eco::API::Common::People::Entries#entry
125
126
127
128
129
130
|
# File 'lib/eco/api/common/people/entries.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")
entry(id: id, external_id: external_id, email: email, strict: strict)
end
|
#group_by_supervisor ⇒ Object
173
174
175
|
# File 'lib/eco/api/common/people/entries.rb', line 173
def group_by_supervisor
to_h(:supervisor_id)
end
|
#id(*args) ⇒ Object
58
59
60
|
# File 'lib/eco/api/common/people/entries.rb', line 58
def id(*args)
attr('id', *args).first
end
|
#policy_group_ids_all(ids) ⇒ Object
85
86
87
|
# File 'lib/eco/api/common/people/entries.rb', line 85
def policy_group_ids_all(ids)
attr("policy_group_ids", tags, default_modifier.all.insensitive)
end
|
#policy_group_ids_any(ids) ⇒ Object
81
82
83
|
# File 'lib/eco/api/common/people/entries.rb', line 81
def policy_group_ids_any(ids)
attr("policy_group_ids", tags, default_modifier.any.insensitive)
end
|
#to_h(attr = "id") ⇒ Object
177
178
179
|
# File 'lib/eco/api/common/people/entries.rb', line 177
def to_h(attr = "id")
super(attr || "id")
end
|