Class: Coolhand::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/coolhand/configuration.rb

Overview

Handles all configuration settings for the gem.

Constant Summary collapse

DEFAULT_EXCLUDE_API_PATTERNS =
YAML.load_file(
  File.join(__dir__, "default_exclude_api_patterns.yml")
).freeze
DEFAULT_INTERCEPT_ADDRESSES =
YAML.load_file(
  File.join(__dir__, "default_intercept_addresses.yml")
).freeze
BASE_URL_ERROR_MSG =
"base_url must use https:// (or http://localhost / http://127.0.0.1 for local dev)"
LOOPBACK_HOSTS =
%w[localhost 127.0.0.1 ::1].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/coolhand/configuration.rb', line 23

def initialize
  # Set defaults
  @environment = "production"
  @api_key = nil
  @silent = false
  @intercept_addresses = DEFAULT_INTERCEPT_ADDRESSES.dup
  self.base_url = "https://coolhandlabs.com/api"
  @debug_mode = false
  @capture = true
  @exclude_api_patterns = DEFAULT_EXCLUDE_API_PATTERNS.dup
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



20
21
22
# File 'lib/coolhand/configuration.rb', line 20

def api_key
  @api_key
end

#base_urlObject

Returns the value of attribute base_url.



21
22
23
# File 'lib/coolhand/configuration.rb', line 21

def base_url
  @base_url
end

#captureObject

Returns the value of attribute capture.



20
21
22
# File 'lib/coolhand/configuration.rb', line 20

def capture
  @capture
end

#debug_modeObject

Returns the value of attribute debug_mode.



20
21
22
# File 'lib/coolhand/configuration.rb', line 20

def debug_mode
  @debug_mode
end

#environmentObject

Returns the value of attribute environment.



20
21
22
# File 'lib/coolhand/configuration.rb', line 20

def environment
  @environment
end

#exclude_api_patternsObject

Returns the value of attribute exclude_api_patterns.



20
21
22
# File 'lib/coolhand/configuration.rb', line 20

def exclude_api_patterns
  @exclude_api_patterns
end

#intercept_addressesObject

Returns the value of attribute intercept_addresses.



21
22
23
# File 'lib/coolhand/configuration.rb', line 21

def intercept_addresses
  @intercept_addresses
end

#silentObject

Returns the value of attribute silent.



20
21
22
# File 'lib/coolhand/configuration.rb', line 20

def silent
  @silent
end

Instance Method Details

#validate!Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/coolhand/configuration.rb', line 49

def validate!
  # Validate API Key after configuration
  if api_key.nil?
    Coolhand.log "❌ Coolhand Error: API Key is required. Please set it in the configuration."
    raise Error, "API Key is required"
  end

  # Validate intercept_addresses after configuration
  if intercept_addresses.nil? || intercept_addresses.empty?
    Coolhand.log "❌ Coolhand Error: Intercept addresses cannot be empty. Please set it in the configuration."
    raise Error, "Intercept addresses cannot be empty"
  end

  unless valid_base_url?(base_url)
    Coolhand.log "❌ Coolhand Error: #{BASE_URL_ERROR_MSG}"
    raise Error, BASE_URL_ERROR_MSG
  end
end