Sha256: 0be8a9bb75bb003e95362867b31cfdbfff3f126ebf67f0221a0a73bbc0ee0182
Contents?: true
Size: 1.95 KB
Versions: 3
Compression:
Stored size: 1.95 KB
Contents
class Eco::API::UseCases::Default::People::SupersCyclicIdentify < Eco::API::Common::Loaders::UseCase name "identify-cyclic-supers" type :export attr_reader :people def main(people, session, options, usecase) options[:end_get] = false save!(cyclic_sets) end private def cyclic_sets Eco::API::Common::People::SupervisorHelpers.identify_cyclic_chains(people) end def file @file ||= options.dig(:output, :file) || "cyclic_supers.txt" end def save!(data) if data.empty? session.logger.info("There were no cyclic supervisors identified!!") return end ext = File.extname(file).downcase.delete(".") File.open(file, "w") do |fd| case ext when "txt" create_file(data, file: file, format: :txt) when "html" log(:warn) { "html is still not supported" } exit(1) # create_file(data, file: file, format: :html) when "json" log(:warn) { "json is still not supported" } exit(1) # create_file(data, file: file, format: :json) end end end def create_file(sets, file:, format: :txt) File.open(file, "w") do |fd| fd << sets_to_str(sets, format: format) end puts "Generated file #{file}" end def sets_to_str(sets, format: :txt) raise "Required Array. Given: #{sets.class}" unless sets.is_a?(Array) "".tap do |str| sets.each do |set| str << set_to_str(set, format: format) end end end def set_to_str(set, lev: 0, format: :txt) raise "Required Array. Given: #{set.class}" unless set.is_a?(Array) "".tap do |str| entry = set.shift str << "#{" " * lev}" str << lev > 0 ? "+-#{lev}- " : "" str << entry.name str << " (#{entry.external_id}|#{entry.email}|#{entry.id})\n" next unless set && !set.empty? str << set_to_str(set, lev: lev + 1, format: format) end end end
Version data entries
3 entries across 3 versions & 1 rubygems