Class: Eco::API::UseCases::DefaultCases::ToCsvDetailedCase

Inherits:
Eco::API::UseCases::DefaultCase show all
Defined in:
lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb

Instance Method Summary collapse

Methods inherited from Eco::API::UseCases::DefaultCase

#initialize

Constructor Details

This class inherits a constructor from Eco::API::UseCases::DefaultCase

Instance Method Details

#processObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb', line 7

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

     = session.

    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
      header += ["Login Methods"] if .any_optional?
      header += ["Subordinates"]
      header += ["Landing Page"]

      csv << header
      people.each do |person|
        data = session.new_entry(person, dependencies: deps).to_hash.values
        person_abilities = (person. && person..permissions_custom) || {}
        data += abilities.map {|key| person_abilities[key] || "no access"}
        if .any_optional?
          logins = (person. && person..) || []
          data.push(.to_name(logins).join("|"))
        end
        data.push(person.subordinates)

        if person. && landing_id = person..landing_page_id
          data.push(landing_id)
        end

        csv << data
      end
    end
    true
  end
end