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-3.7.0 lib/licensed/report.rb
licensed-3.6.0 lib/licensed/report.rb
licensed-3.5.0 lib/licensed/report.rb
licensed-3.4.4 lib/licensed/report.rb
licensed-3.4.3 lib/licensed/report.rb
licensed-3.4.2 lib/licensed/report.rb
licensed-3.4.1 lib/licensed/report.rb
licensed-3.4.0 lib/licensed/report.rb
licensed-3.3.1 lib/licensed/report.rb
licensed-3.3.0 lib/licensed/report.rb
licensed-3.2.3 lib/licensed/report.rb
licensed-3.2.2 lib/licensed/report.rb
licensed-3.2.1 lib/licensed/report.rb
licensed-3.2.0 lib/licensed/report.rb