Class: Boffin::Config
- Inherits:
-
Object
- Object
- Boffin::Config
- Defined in:
- lib/boffin/config.rb
Overview
Stores configuration state to be used in various parts of the app. You will likely not need to instantiate Config directly.
Instance Attribute Summary collapse
-
#cache_expire_secs ⇒ Fixnum
Number of seconds to cache the results of
Tracker.top
. -
#days_window_secs ⇒ Fixnum
Number of seconds to maintain the daily hit interval window.
-
#hours_window_secs ⇒ Fixnum
Number of seconds to maintain the hourly hit interval window.
-
#months_window_secs ⇒ Fixnum
Number of seconds to maintain the monthly hit interval window.
-
#namespace ⇒ String
The namespace to prefix all Redis keys with.
-
#redis ⇒ Redis
The Redis instance that will be used to store hit data.
Instance Method Summary collapse
-
#initialize(opts = {}) {|self| ... } ⇒ Config
constructor
A new instance of Config.
-
#merge(updates = {}) ⇒ Config
Creates a copy of self and updates the copy with the values provided.
-
#update(updates = {}) ⇒ self
Updates self with the values provided.
Constructor Details
#initialize(opts = {}) {|self| ... } ⇒ Config
Returns a new instance of Config.
23 24 25 26 |
# File 'lib/boffin/config.rb', line 23 def initialize(opts = {}, &block) yield(self) if block_given? update(opts) end |
Instance Attribute Details
#cache_expire_secs ⇒ Fixnum
Returns Number of seconds to cache the results of Tracker.top
.
86 87 88 |
# File 'lib/boffin/config.rb', line 86 def cache_expire_secs @cache_expire_secs ||= 15 * 60 # 15 minutes end |
#days_window_secs ⇒ Fixnum
Returns Number of seconds to maintain the daily hit interval window.
74 75 76 |
# File 'lib/boffin/config.rb', line 74 def days_window_secs @days_window_secs ||= 3 * 30 * 24 * 3600 # 3 months end |
#hours_window_secs ⇒ Fixnum
Returns Number of seconds to maintain the hourly hit interval window.
68 69 70 |
# File 'lib/boffin/config.rb', line 68 def hours_window_secs @hours_window_secs ||= 3 * 24 * 3600 # 3 days end |
#months_window_secs ⇒ Fixnum
Returns Number of seconds to maintain the monthly hit interval window.
80 81 82 |
# File 'lib/boffin/config.rb', line 80 def months_window_secs @months_window_secs ||= 3 * 12 * 30 * 24 * 3600 # 3 years end |
#namespace ⇒ String
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.
56 57 58 59 60 61 62 63 64 |
# 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 ⇒ Redis
The Redis instance that will be used to store hit data
48 49 50 |
# File 'lib/boffin/config.rb', line 48 def redis @redis ||= Redis.connect end |
Instance Method Details
#merge(updates = {}) ⇒ Config
Creates a copy of self and updates the copy with the values provided
42 43 44 |
# File 'lib/boffin/config.rb', line 42 def merge(updates = {}) dup.update(updates) end |
#update(updates = {}) ⇒ self
Updates self with the values provided
32 33 34 35 36 |
# File 'lib/boffin/config.rb', line 32 def update(updates = {}) tap do |conf| updates.each_pair { |k, v| conf.send(:"#{k}=", v) } end end |