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.



132
133
134
135
136
# File 'lib/abmeter.rb', line 132

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

Instance Attribute Details

#api_keyObject

API configuration



117
118
119
# File 'lib/abmeter.rb', line 117

def api_key
  @api_key
end

#base_urlObject

Base URL for API endpoints



118
119
120
# File 'lib/abmeter.rb', line 118

def base_url
  @base_url
end

#error_callbackObject

Proc called on errors



130
131
132
# File 'lib/abmeter.rb', line 130

def error_callback
  @error_callback
end

#fetch_intervalObject

Seconds between config fetches (default: 60)



125
126
127
# File 'lib/abmeter.rb', line 125

def fetch_interval
  @fetch_interval
end

#flush_intervalObject

Performance tuning



124
125
126
# File 'lib/abmeter.rb', line 124

def flush_interval
  @flush_interval
end

#log_levelObject

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



129
130
131
# File 'lib/abmeter.rb', line 129

def log_level
  @log_level
end

#loggerObject

Logging and error handling



128
129
130
# File 'lib/abmeter.rb', line 128

def logger
  @logger
end

#static_configObject

Static configuration (alternative to API)



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

def static_config
  @static_config
end

Instance Method Details

#inspectObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/abmeter.rb', line 145

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



138
139
140
141
142
143
# File 'lib/abmeter.rb', line 138

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