Sha256: 5dee48626e561d13f3b9e088cb67c319130b7c09f81fac5706cc9018a28e4ab3

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Mihari
  module Concerns
    #
    # Configurable concern
    #
    module Configurable
      extend ActiveSupport::Concern

      #
      # Check whether there are configuration key-values or not
      #
      # @return [Boolean]
      #
      def configuration_keys?
        return true if self.class.configuration_keys.empty?

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

      #
      # Check whether it is configured or not
      #
      # @return [Boolean]
      #
      def configured?
        configuration_keys? || api_key?
      end

      class_methods do
        #
        # Configuration items
        #
        # @return [Array<Hash>] Configuration values as a list of hash. Returns nil if there is any keys.
        #
        def configuration_items
          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 configuration keys
        #
        def configuration_keys
          []
        end
      end

      private

      #
      # Check whether API key is set or not
      #
      # @return [Boolean]
      #
      def api_key?
        value = method(:api_key).call
        !value.nil?
      rescue NameError
        true
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mihari-7.3.2 lib/mihari/concerns/configurable.rb
mihari-7.3.1 lib/mihari/concerns/configurable.rb
mihari-7.3.0 lib/mihari/concerns/configurable.rb
mihari-7.2.0 lib/mihari/concerns/configurable.rb
mihari-7.1.3 lib/mihari/concerns/configurable.rb
mihari-7.1.2 lib/mihari/concerns/configurable.rb
mihari-7.1.1 lib/mihari/concerns/configurable.rb
mihari-7.1.0 lib/mihari/concerns/configurable.rb
mihari-7.0.5 lib/mihari/concerns/configurable.rb
mihari-7.0.4 lib/mihari/concerns/configurable.rb
mihari-7.0.3 lib/mihari/concerns/configurable.rb
mihari-7.0.2 lib/mihari/concerns/configurable.rb
mihari-7.0.1 lib/mihari/concerns/configurable.rb
mihari-7.0.0 lib/mihari/concerns/configurable.rb