Sha256: 5dbe3ff49f588018dbccf2c61b6d0e7c66e402cbf40b8db4f3c9438ce8a6656e

Contents?: true

Size: 1.1 KB

Versions: 3

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Mihari
  module Mixins
    module Configurable
      #
      # Check whether it is configured or not
      #
      # @return [Boolean]
      #
      def configured?
        return true if configuration_keys.empty?

        configuration_keys.all? { |key| Mihari.config.send(key) } || api_key?
      end

      #
      # Configuration values
      #
      # @return [Array<Hash>, nil] Configuration values as a list of hash. Returns nil if there is any keys.
      #
      def configuration_values
        return nil if configuration_keys.empty?

        configuration_keys.map do |key|
          value = Mihari.config.send(key)
          value = "REDACTED" if value && Mihari.config.hide_config_values
          { key: key.upcase, value: value }
        end
      end

      #
      # Configuration keys
      #
      # @return [Array<String>] A list of cofiguration keys
      #
      def configuration_keys
        []
      end

      private

      def api_key?
        value = method(:api_key).call
        !value.nil?
      rescue NameError
        true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mihari-5.2.2 lib/mihari/mixins/configurable.rb
mihari-5.2.1 lib/mihari/mixins/configurable.rb
mihari-5.2.0 lib/mihari/mixins/configurable.rb