Sha256: 3f5c7940050de6e6002d18b1bce788cc2cb2635ea55fb9228c7d368cc87b4b13
Contents?: true
Size: 1.47 KB
Versions: 5
Compression:
Stored size: 1.47 KB
Contents
module Eco module API class UseCases class DefaultCases class ToCsvDetailedCase < DefaultCase def process @cases.define("to-csv-detailed", type: :export) do |people, session, options, usecase| unless people && !people.empty? session.logger.warn("No source people to create the file... aborting!") next false end unless file = options[:file] || options.dig(:export, :file, :name) session.logger.error("Destination file not specified") next false end abilities = session.new_preset([]).keys session.logger.info("going to create file: #{file}") CSV.open(file, "w") do |csv| deps = {"supervisor_id" => {people: people}} header = session.new_entry(people.first, dependencies: deps).to_hash.keys header += abilities csv << header people.each do |person| data = session.new_entry(person, dependencies: deps).to_hash.values person_abilities = (person.account && person.account.permissions_custom) || {} data += abilities.map {|key| person_abilities[key] || "no access"} csv << data end end true end end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems