Sha256: ae485e4fa0d25bdb4b5a4aed35f7ea1df6bd71c4586903220687719616019b5c

Contents?: true

Size: 928 Bytes

Versions: 34

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module Licensed
  class Report < Hash
    attr_reader :name
    attr_reader :target
    def initialize(name:, target:)
      super()
      @name = name
      @target = target
    end

    def reports
      @reports ||= []
    end

    def errors
      @errors ||= []
    end

    def warnings
      @warnings ||= []
    end

    def all_reports
      result = []
      result << self
      result.push(*reports.flat_map(&:all_reports))
    end

    # Returns the data from the report as a hash
    def to_h
      # add name, errors and warnings if they have real data
      output = {}
      output["name"] = name unless name.to_s.empty?
      output["errors"] = errors.dup if errors.any?
      output["warnings"] = warnings.dup if warnings.any?

      # merge the hash data from the report.  command-specified data always
      # overwrites local data
      output.merge(super)
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
licensed-5.0.0 lib/licensed/report.rb
licensed-4.5.0 lib/licensed/report.rb
licensed-4.4.0 lib/licensed/report.rb
licensed-4.3.1 lib/licensed/report.rb
licensed-4.3.0 lib/licensed/report.rb
licensed-4.2.0 lib/licensed/report.rb
licensed-4.1.0 lib/licensed/report.rb
licensed-4.0.4 lib/licensed/report.rb
licensed-4.0.3 lib/licensed/report.rb
licensed-4.0.2 lib/licensed/report.rb
licensed-4.0.1 lib/licensed/report.rb
licensed-4.0.0 lib/licensed/report.rb
licensed-3.9.1 lib/licensed/report.rb
licensed-3.9.0 lib/licensed/report.rb
licensed-3.8.0 lib/licensed/report.rb
licensed-3.7.5 lib/licensed/report.rb
licensed-3.7.4 lib/licensed/report.rb
licensed-3.7.3 lib/licensed/report.rb
licensed-3.7.2 lib/licensed/report.rb
licensed-3.7.1 lib/licensed/report.rb