Sha256: ed3edeef216194af95c84263e0855e76006534b546792c5388742a49aa93b290

Contents?: true

Size: 1.91 KB

Versions: 13

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

# DeployRubygem - deploy a gem using rake
# Containing a class
module DeployRubygem
  # Using Inspec to deploy and manage Inspec
  class InspecTestorResult
    attr_reader :success_control, :success_result, :failed_control, :failed_result, :pending_control, :pending_result, :success_profiles, :failed_profiles

    def initialize(as_json)
      @as_json = as_json
      @success_control = 0
      @success_result = 0
      @failed_control = 0
      @failed_result = 0
      @pending_control = 0
      @pending_result = 0
      @success_profiles = []
      @failed_profiles = []
      results
    end

    def profile
      @as_json['profiles'].first
    end

    def status
      profile['status']
    end

    def controls
      profile['controls']
    end

    def result_summary
      {
        success_control: success_control,
        success_result: success_result,
        failed_control: failed_control,
        failed_result: failed_result,
        pending_control: pending_control,
        pending_result: pending_result
      }
    end

    private

    def check_steps(item_result)
      failed_steps = false
      case item_result['status']
      when 'passed'
        @success_result += 1
        @success_profiles << item_result['code_desc']
      when 'failed'
        @failed_result += 1
        @failed_profiles << item_result['code_desc']
        failed_steps = true
      else
        @pending_result += 1
        @pending_control += 1
        failed_steps = true
      end
      failed_steps
    end

    def results
      controls.each do |control_result|
        control_as_fail = false
        control_result['results'].each do |item_result|
          step_result = check_steps(item_result)
          control_as_fail = step_result if step_result
        end
        if control_as_fail
          @failed_control += 1
        else
          @success_control += 1
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
deploy_rubygem-0.60.47 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.46 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.45 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.44 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.43 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.41 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.40 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.39 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.38 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.37 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.36 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.35 lib/deploy_rubygem/inspec_result.rb
deploy_rubygem-0.60.34 lib/deploy_rubygem/inspec_result.rb