Class: ABMeter::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



113
114
115
116
117
# File 'lib/abmeter.rb', line 113

def initialize
  @flush_interval = DEFAULT_FLUSH_INTERVAL
  @fetch_interval = DEFAULT_FETCH_INTERVAL
  @logger = detect_logger
end

Instance Attribute Details

#api_keyObject

API configuration



98
99
100
# File 'lib/abmeter.rb', line 98

def api_key
  @api_key
end

#base_urlObject

Base URL for API endpoints



99
100
101
# File 'lib/abmeter.rb', line 99

def base_url
  @base_url
end

#error_callbackObject

Proc called on errors



111
112
113
# File 'lib/abmeter.rb', line 111

def error_callback
  @error_callback
end

#fetch_intervalObject

Seconds between config fetches (default: 60)



106
107
108
# File 'lib/abmeter.rb', line 106

def fetch_interval
  @fetch_interval
end

#flush_intervalObject

Performance tuning



105
106
107
# File 'lib/abmeter.rb', line 105

def flush_interval
  @flush_interval
end

#log_levelObject

Log level (:debug, :info, :warn, :error)



110
111
112
# File 'lib/abmeter.rb', line 110

def log_level
  @log_level
end

#loggerObject

Logging and error handling



109
110
111
# File 'lib/abmeter.rb', line 109

def logger
  @logger
end

#static_configObject

Static configuration (alternative to API)



102
103
104
# File 'lib/abmeter.rb', line 102

def static_config
  @static_config
end

Instance Method Details

#inspectObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/abmeter.rb', line 126

def inspect
  masked_key = api_key ? "#{api_key[0..3]}...#{api_key[-4..]}" : nil
  config_type = static_config ? 'static' : 'API'

  <<~CONFIG.strip
    #ABMeter::Config {
      type: #{config_type},
      api_key: #{masked_key.inspect},
      base_url: #{base_url.inspect},
      flush_interval: #{flush_interval.inspect},
      fetch_interval: #{fetch_interval.inspect},
      logger: #{logger.class.name}
    }
  CONFIG
end

#validate!Object



119
120
121
122
123
124
# File 'lib/abmeter.rb', line 119

def validate!
  unless static_config
    raise 'No API key provided' if api_key.nil?
    raise 'No API URL provided' if base_url.nil?
  end
end