Sha256: 98326c8fcec2ccb5e1f7734d0e372a9ac9bd530949c889d38803547238bbf3b4
Contents?: true
Size: 1.71 KB
Versions: 5
Compression:
Stored size: 1.71 KB
Contents
class Eco::API::UseCases::Default::People::CleanUnknownTags < Eco::API::Common::Loaders::UseCase name "clean-unknown-tags" type :transform REGISTER_TAGS = [ "EVENT", "INJURY", "RISK", "CONTRACTOR", "PERMIT", "AUDIT", "JSEA", "TRAINING", "INDUCTION", "MEETING", "PPE", "CHEMICAL", "PLANT", "ASSET", "POLICY", "IDEA", "REPORTS" ] def main(people, session, options, usecase) update = session.new_job("main", "update", :update, usecase) people.each do |person| unknown_tags = person.filter_tags.reject { |tag| tag?(tag) } person.filter_tags -= unknown_tags removed_tag!(*unknown_tags) if (tag = default_tag(person)) && !tag?(tag) removed_tag!(tag) micro.refresh_default_tag(person.entry, person, options) end update.add(person) end log(:info) { msg = "Here list of the #{removed_tags.count} removed locations..." msg + "\n • " + removed_tags.sort.join("\n • ") } end private def default_tag(person) return nil unless account = person.account account.default_tag end def register_tags @register_tags ||= self.class::REGISTER_TAGS.compact.map(&:upcase) end def removed_tag!(*tags) @removed_tags = removed_tags | tags end def removed_tags @removed_tags ||= [] end def tag?(value) return false if value.nil? return true if tagtree.tag?(value) return false if clean_register_tags? register_tags.any? { |reg| value.upcase == reg } end def tagtree @tagtree ||= session.tagtree(live: true, merge: true) end def clean_register_tags? options.dig(:usecase, :clear_register_tags) end end
Version data entries
5 entries across 5 versions & 1 rubygems