Sha256: 7e2d418fcb01edf6231d061924cba153412c68bbbaa9fdfa8c52c609d5cd6507

Contents?: true

Size: 1.15 KB

Versions: 27

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true
module Licensed
  module Reporters
    class YamlReporter < Reporter
      def report_run(command)
        super do |report|
          result = yield report

          report["apps"] = report.reports.map(&:to_h) if report.reports.any?
          shell.info sanitize(report.to_h).to_yaml

          result
        end
      end

      def report_app(app)
        super do |report|
          result = yield report
          report["sources"] = report.reports.map(&:to_h) if report.reports.any?
          result
        end
      end

      def report_source(source)
        super do |report|
          result = yield report
          report["dependencies"] = report.reports.map(&:to_h) if report.reports.any?
          result
        end
      end

      def sanitize(object)
        case object
        when String, TrueClass, FalseClass, Numeric
          object
        when Array
          object.compact.map { |item| sanitize(item) }
        when Hash
          object.reject { |_, v| v.nil? }
                .map { |k, v| [k.to_s, sanitize(v)] }
                .to_h
        else
          object.to_s
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
licensed-3.1.0 lib/licensed/reporters/yaml_reporter.rb
licensed-3.0.1 lib/licensed/reporters/yaml_reporter.rb
licensed-3.0.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.15.2 lib/licensed/reporters/yaml_reporter.rb
licensed-2.15.1 lib/licensed/reporters/yaml_reporter.rb
licensed-2.15.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.14.4 lib/licensed/reporters/yaml_reporter.rb
licensed-2.14.3 lib/licensed/reporters/yaml_reporter.rb
licensed-2.14.2 lib/licensed/reporters/yaml_reporter.rb
licensed-2.14.1 lib/licensed/reporters/yaml_reporter.rb
licensed-2.14.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.13.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.12.2 lib/licensed/reporters/yaml_reporter.rb
licensed-2.12.1 lib/licensed/reporters/yaml_reporter.rb
licensed-2.12.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.11.1 lib/licensed/reporters/yaml_reporter.rb
licensed-2.11.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.10.0 lib/licensed/reporters/yaml_reporter.rb
licensed-2.9.2 lib/licensed/reporters/yaml_reporter.rb
licensed-2.9.1 lib/licensed/reporters/yaml_reporter.rb