Class: Coolhand::Configuration
- Inherits:
-
Object
- Object
- Coolhand::Configuration
- 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
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#capture ⇒ Object
Returns the value of attribute capture.
-
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#exclude_api_patterns ⇒ Object
Returns the value of attribute exclude_api_patterns.
-
#intercept_addresses ⇒ Object
Returns the value of attribute intercept_addresses.
-
#silent ⇒ Object
Returns the value of attribute silent.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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_key ⇒ Object
Returns the value of attribute api_key.
20 21 22 |
# File 'lib/coolhand/configuration.rb', line 20 def api_key @api_key end |
#base_url ⇒ Object
Returns the value of attribute base_url.
21 22 23 |
# File 'lib/coolhand/configuration.rb', line 21 def base_url @base_url end |
#capture ⇒ Object
Returns the value of attribute capture.
20 21 22 |
# File 'lib/coolhand/configuration.rb', line 20 def capture @capture end |
#debug_mode ⇒ Object
Returns the value of attribute debug_mode.
20 21 22 |
# File 'lib/coolhand/configuration.rb', line 20 def debug_mode @debug_mode end |
#environment ⇒ Object
Returns the value of attribute environment.
20 21 22 |
# File 'lib/coolhand/configuration.rb', line 20 def environment @environment end |
#exclude_api_patterns ⇒ Object
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_addresses ⇒ Object
Returns the value of attribute intercept_addresses.
21 22 23 |
# File 'lib/coolhand/configuration.rb', line 21 def intercept_addresses @intercept_addresses end |
#silent ⇒ Object
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 |