class Boffin::Config
Stores configuration state to be used in various parts of the app. You will likely not need to instantiate Config
directly.
Attributes
Public Class Methods
@param [Hash] opts
The parameters to create a new Config instance
@option opts [Redis] :redis @option opts [String] :namespace @option opts [Fixnum] :hours_window_secs @option opts [Fixnum] :days_window_secs @option opts [Fixnum] :months_window_secs @option opts [Fixnum] :cache_expire_secs @yield [self]
# File lib/boffin/config.rb, line 23 def initialize(opts = {}, &block) yield(self) if block_given? update(opts) end
Public Instance Methods
@return [Fixnum]
Number of seconds to cache the results of `Tracker.top`
# File lib/boffin/config.rb, line 86 def cache_expire_secs @cache_expire_secs ||= 15 * 60 # 15 minutes end
@return [Fixnum]
Number of seconds to maintain the daily hit interval window
# File lib/boffin/config.rb, line 74 def days_window_secs @days_window_secs ||= 3 * 30 * 24 * 3600 # 3 months end
@return [Fixnum]
Number of seconds to maintain the hourly hit interval window
# File lib/boffin/config.rb, line 68 def hours_window_secs @hours_window_secs ||= 3 * 24 * 3600 # 3 days end
Creates a copy of self and updates the copy with the values provided @param [Hash] updates
A hash of options to merge with the instance
@return [Config] the new Config
instance with updated values
# File lib/boffin/config.rb, line 42 def merge(updates = {}) dup.update(updates) end
@return [Fixnum]
Number of seconds to maintain the monthly hit interval window
# File lib/boffin/config.rb, line 80 def months_window_secs @months_window_secs ||= 3 * 12 * 30 * 24 * 3600 # 3 years end
The namespace to prefix all Redis keys with. Defaults to ‘“boffin”` or `“boffin:<env>”` if `RACK_ENV` or `RAILS_ENV` are present in the environment. @return [String]
# File lib/boffin/config.rb, line 56 def namespace @namespace ||= begin if (env = ENV['RACK_ENV'] || ENV['RAILS_ENV']) "boffin:#{env}" else "boffin" end end end
The Redis instance that will be used to store hit data @return [Redis] the active Redis connection
# File lib/boffin/config.rb, line 48 def redis @redis ||= Redis.connect end
Updates self with the values provided @param [Hash] updates
A hash of options to update the config instance with
@return [self]
# File lib/boffin/config.rb, line 32 def update(updates = {}) tap do |conf| updates.each_pair { |k, v| conf.send(:"#{k}=", v) } end end