Sha256: 94dc3cd5c9b505d8dd60384b8169d4a69340adae043cadb5b929bb575fd424f3

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'forwardable'
require 'contrast/utils/object_share'

module Contrast
  module Config
    # This is the base for our configuration classes. It is intended to facilitate the translation of the Common
    # Configuration settings to usable Ruby classes.
    module BaseConfiguration
      extend Forwardable

      def to_hash
        hsh = {}
        instance_variables.each do |iv|
          # strip the '@' to get the key
          key = iv.to_s[1..]
          hsh[key] = send(key.to_sym)
        end
        hsh
      end

      def assign_value_to_path_array dot_path_array, value
        current_level = self
        dot_path_array[0...-1].each do |segment|
          segment = segment.tr('-', '_')
          current_level = current_level.send(segment) if current_level.cs__respond_to?(segment)
        end
        last_entry = dot_path_array[-1]
        if current_level.nil? == false && current_level.cs__respond_to?(last_entry)
          current_level.send("#{ last_entry }=", value)
        end
        nil
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
contrast-agent-6.2.0 lib/contrast/config/base_configuration.rb
contrast-agent-6.1.2 lib/contrast/config/base_configuration.rb
contrast-agent-6.1.1 lib/contrast/config/base_configuration.rb
contrast-agent-6.1.0 lib/contrast/config/base_configuration.rb