Sha256: bfd9b23da42ea886716c72fce6b34e882f2d94a4f1e13582c2357927414134bb

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 KB

Contents

module Eco
  module API
    module UseCases
      class DefaultCases
        class ToCsvDetailedCase < BaseCase

          def process
            @cases.define("to-csv-detailed", type: :export) do |people, session, options|
              unless people && !people.empty?
                session.logger.warn("No source people to create the file... aborting!")
                next false
              end

              unless file = options[:file]
                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

9 entries across 9 versions & 1 rubygems

Version Path
eco-helpers-0.6.17 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.16 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.15 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.13 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.12 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.11 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.9 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.8 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb
eco-helpers-0.6.7 lib/eco/api/usecases/default_cases/to_csv_detailed_case.rb