Class: Dislogger::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dislogger/configuration.rb', line 12

def initialize
  @discord_webhook_url = nil
  @bot_username = 'Error Logger'
  @backtrace_lines_limit = 5
  @enabled_environments = %w[production staging]
  @environment = nil
  @error_color_map = {
    500 => 15158332, # Red for server errors
    404 => 3447003,  # Blue for not found
    422 => 16776960, # Yellow for validation errors
    403 => 15105570, # Orange for forbidden
    default: 10181046 # Gray for others
  }
end

Instance Attribute Details

#backtrace_lines_limitObject

Returns the value of attribute backtrace_lines_limit.



5
6
7
# File 'lib/dislogger/configuration.rb', line 5

def backtrace_lines_limit
  @backtrace_lines_limit
end

#bot_usernameObject

Returns the value of attribute bot_username.



5
6
7
# File 'lib/dislogger/configuration.rb', line 5

def bot_username
  @bot_username
end

#discord_webhook_urlObject

Returns the value of attribute discord_webhook_url.



5
6
7
# File 'lib/dislogger/configuration.rb', line 5

def discord_webhook_url
  @discord_webhook_url
end

#enabled_environmentsObject

Returns the value of attribute enabled_environments.



5
6
7
# File 'lib/dislogger/configuration.rb', line 5

def enabled_environments
  @enabled_environments
end

#environmentObject

Returns the value of attribute environment.



5
6
7
# File 'lib/dislogger/configuration.rb', line 5

def environment
  @environment
end

#error_color_mapObject

Returns the value of attribute error_color_map.



5
6
7
# File 'lib/dislogger/configuration.rb', line 5

def error_color_map
  @error_color_map
end

Instance Method Details

#enabled?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/dislogger/configuration.rb', line 35

def enabled?
  return false if environment.nil? || enabled_environments.empty?
  enabled_environments.include?(environment)
end

#validate!Object



27
28
29
30
31
32
33
# File 'lib/dislogger/configuration.rb', line 27

def validate!
  raise Errors::ConfigurationError, 'Discord webhook URL is required' unless discord_webhook_url.present?
  raise Errors::ConfigurationError, 'Bot username is required' unless bot_username.present?
  raise Errors::ConfigurationError, 'Enabled environments must be an array' unless enabled_environments.is_a?(Array)
  raise Errors::ConfigurationError, 'Environment must be present' unless environment.present?
  true
end