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.



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

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

Instance Attribute Details

#api_keyObject

API configuration



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

def api_key
  @api_key
end

#base_urlObject

Base URL for API endpoints



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

def base_url
  @base_url
end

#error_callbackObject

Proc called on errors



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

def error_callback
  @error_callback
end

#fetch_intervalObject

Seconds between config fetches (default: 60)



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

def fetch_interval
  @fetch_interval
end

#flush_intervalObject

Performance tuning



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

def flush_interval
  @flush_interval
end

#log_levelObject

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



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

def log_level
  @log_level
end

#loggerObject

Logging and error handling



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

def logger
  @logger
end

#static_configObject

Static configuration (alternative to API)



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

def static_config
  @static_config
end

Instance Method Details

#inspectObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/abmeter.rb', line 139

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



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

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