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

cache_expire_secs[W]
days_window_secs[W]
hours_window_secs[W]
months_window_secs[W]
namespace[W]
redis[W]

Public Class Methods

new(opts = {}) { |self| ... } click to toggle source

@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

cache_expire_secs() click to toggle source

@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
days_window_secs() click to toggle source

@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
hours_window_secs() click to toggle source

@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
merge(updates = {}) click to toggle source

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
months_window_secs() click to toggle source

@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
namespace() click to toggle source

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
redis() click to toggle source

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
update(updates = {}) click to toggle source

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