Module: Contrast::Components::ComponentBase

Overview

All components should inherit from this, whether Interfaces, InstanceMethods or ClassMethods.

Constant Summary collapse

ENABLE =
'enable'

Constants included from Contrast::Config::Diagnostics::Tools

Contrast::Config::Diagnostics::Tools::CHECK

Constants included from Contrast::Config::Diagnostics::SingletonTools

Contrast::Config::Diagnostics::SingletonTools::API_CREDENTIALS, Contrast::Config::Diagnostics::SingletonTools::CONTRAST_MARK

Instance Method Summary collapse

Methods included from Contrast::Config::Diagnostics::Tools

#add_effective_config_values, #add_single_effective_value

Methods included from Contrast::Config::Diagnostics::SingletonTools

#flatten_settings, #to_config_values, #update_config, #value_to_s

Instance Method Details

#canon_nameString

Used for config diagnostics. Override per rule.

Returns:



20
21
22
# File 'lib/contrast/components/base.rb', line 20

def canon_name
  Contrast::Utils::ObjectShare::EMPTY_STRING
end

#config_valuesArray

Used for config diagnostics. Override per rule.

Returns:

  • (Array)


27
28
29
# File 'lib/contrast/components/base.rb', line 27

def config_values
  Contrast::Utils::ObjectShare::EMPTY_ARRAY
end

#false?(config_param) ⇒ Boolean

use this to determine if the configuration value is literally boolean false or some form of the word ‘false`, regardless of case. It should be used for those values which default to `true` as they should only treat a value explicitly set to `false` as such.

Parameters:

  • config_param (Boolean, String)

    the value to check

Returns:

  • (Boolean)

    should the value be treated as ‘false`



38
39
40
41
42
43
44
# File 'lib/contrast/components/base.rb', line 38

def false? config_param
  return false if config_param == true
  return true if config_param == false
  return false unless config_param.cs__is_a?(String)

  config_param.downcase == Contrast::Utils::ObjectShare::FALSE
end

#file_exists?(path) ⇒ Boolean

check if file exists at all

Parameters:

Returns:

  • (Boolean)


78
79
80
81
82
# File 'lib/contrast/components/base.rb', line 78

def file_exists? path
  return false unless path

  File.exist?(path)
end

#stringify_array(val, join_char = ',') ⇒ String, Object

attempts to stringify the config value if it is an array with the join char

Parameters:

  • val (Object)

    val to stringify

  • join_char (String, ',') (defaults to: ',')

    join character defaults to ‘,’

Returns:

  • (String, Object)

    the stringified val or the object as is



97
98
99
100
101
# File 'lib/contrast/components/base.rb', line 97

def stringify_array val, join_char = ','
  return val.join(join_char) if val.cs__is_a?(Array) && val.any?

  val
end

#to_effective_config(effective_config) ⇒ Object

Converts current configuration to effective config values class and appends them to EffectiveConfig class.

Parameters:



88
89
90
# File 'lib/contrast/components/base.rb', line 88

def to_effective_config effective_config
  add_effective_config_values(effective_config, config_values, canon_name)
end

#true?(config_param) ⇒ Boolean

use this to determine if the configuration value is literally boolean true or some form of the word ‘true`, regardless of case. It should be used for those values which default to `false` as they should only treat a value explicitly set to `true` as such.

Parameters:

  • config_param (Boolean, String)

    the value to check

Returns:

  • (Boolean)

    should the value be treated as ‘true`



53
54
55
56
57
58
59
# File 'lib/contrast/components/base.rb', line 53

def true? config_param
  return false if config_param == false
  return true if config_param == true
  return false unless config_param.cs__is_a?(String)

  config_param.downcase == Contrast::Utils::ObjectShare::TRUE
end

#valid_cert?(config_path) ⇒ Boolean

this method will check if a path could be possibly used So for example if we pass a path to a file - we’ll check if there is actually that file and if it’s with certain extension

Parameters:

Returns:

  • (Boolean)


67
68
69
70
71
72
73
74
# File 'lib/contrast/components/base.rb', line 67

def valid_cert? config_path
  return false if config_path.nil?

  exts = %w[.pem .crt .cer].cs__freeze
  return false unless exts.include?(File.extname(config_path))

  true
end