Module: Von::Config
Instance Attribute Summary collapse
-
#bests ⇒ Object
readonly
Returns the value of attribute bests.
-
#currents ⇒ Object
readonly
Returns the value of attribute currents.
-
#daily_format ⇒ Object
Returns the value of attribute daily_format.
-
#hourly_format ⇒ Object
Returns the value of attribute hourly_format.
-
#minutely_format ⇒ Object
Returns the value of attribute minutely_format.
-
#monthly_format ⇒ Object
Returns the value of attribute monthly_format.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#periods ⇒ Object
readonly
Returns the value of attribute periods.
-
#raise_connection_errors ⇒ Object
Returns the value of attribute raise_connection_errors.
-
#weekly_format ⇒ Object
Returns the value of attribute weekly_format.
-
#yearly_format ⇒ Object
Returns the value of attribute yearly_format.
Instance Method Summary collapse
-
#bests_defined_for_counter?(counter) ⇒ Boolean
Returns a True if a best is defined for the given counter.
-
#counter(field, options = {}) ⇒ Object
Configure options for given Counter.
-
#currents_defined_for_counter?(counter) ⇒ Boolean
Returns a True if a current is defined for the given counter.
- #init! ⇒ Object
-
#periods_defined_for_counter?(counter) ⇒ Boolean
Returns a True if a period is defined for the given Counter TODO: these should just take the key, will fix when renaming field.
-
#redis ⇒ Object
Returns the Redis connection.
-
#redis=(arg) ⇒ Object
Set the Redis connection to use.
Instance Attribute Details
#bests ⇒ Object (readonly)
Returns the value of attribute bests.
17 18 19 |
# File 'lib/von/config.rb', line 17 def bests @bests end |
#currents ⇒ Object (readonly)
Returns the value of attribute currents.
18 19 20 |
# File 'lib/von/config.rb', line 18 def currents @currents end |
#daily_format ⇒ Object
Returns the value of attribute daily_format.
12 13 14 |
# File 'lib/von/config.rb', line 12 def daily_format @daily_format end |
#hourly_format ⇒ Object
Returns the value of attribute hourly_format.
13 14 15 |
# File 'lib/von/config.rb', line 13 def hourly_format @hourly_format end |
#minutely_format ⇒ Object
Returns the value of attribute minutely_format.
14 15 16 |
# File 'lib/von/config.rb', line 14 def minutely_format @minutely_format end |
#monthly_format ⇒ Object
Returns the value of attribute monthly_format.
10 11 12 |
# File 'lib/von/config.rb', line 10 def monthly_format @monthly_format end |
#namespace ⇒ Object
Returns the value of attribute namespace.
7 8 9 |
# File 'lib/von/config.rb', line 7 def namespace @namespace end |
#periods ⇒ Object (readonly)
Returns the value of attribute periods.
16 17 18 |
# File 'lib/von/config.rb', line 16 def periods @periods end |
#raise_connection_errors ⇒ Object
Returns the value of attribute raise_connection_errors.
8 9 10 |
# File 'lib/von/config.rb', line 8 def raise_connection_errors @raise_connection_errors end |
#weekly_format ⇒ Object
Returns the value of attribute weekly_format.
11 12 13 |
# File 'lib/von/config.rb', line 11 def weekly_format @weekly_format end |
#yearly_format ⇒ Object
Returns the value of attribute yearly_format.
9 10 11 |
# File 'lib/von/config.rb', line 9 def yearly_format @yearly_format end |
Instance Method Details
#bests_defined_for_counter?(counter) ⇒ Boolean
Returns a True if a best is defined for the given counter
81 82 83 |
# File 'lib/von/config.rb', line 81 def bests_defined_for_counter?(counter) @bests.has_key?(counter.field) end |
#counter(field, options = {}) ⇒ Object
Configure options for given Counter. Configures length of given time period and any other options for the Counter
63 64 65 66 67 68 69 70 |
# File 'lib/von/config.rb', line 63 def counter(field, = {}) field = field.to_sym .each do |option, value| set_period(field, option, value) if Period.exists?(option) set_best(field, value) if option == :best set_current(field, value) if option == :current end end |
#currents_defined_for_counter?(counter) ⇒ Boolean
Returns a True if a current is defined for the given counter
87 88 89 |
# File 'lib/von/config.rb', line 87 def currents_defined_for_counter?(counter) @currents.has_key?(counter.field) end |
#init! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/von/config.rb', line 20 def init! @periods = {} @bests = {} @currents = {} @totals = {} # all keys are prefixed with this namespace self.namespace = 'von' # rescue Redis connection errors self.raise_connection_errors = false # 2013 self.yearly_format = '%Y' # 2013-01 self.monthly_format = '%Y-%m' # 2013-01-02 self.weekly_format = '%Y-%m-%d' # 2013-01-02 self.daily_format = '%Y-%m-%d' # 2013-01-02 12:00 self.hourly_format = '%Y-%m-%d %H:00' # 2013-01-02 12:05 self.minutely_format = '%Y-%m-%d %H:%M' end |
#periods_defined_for_counter?(counter) ⇒ Boolean
Returns a True if a period is defined for the given Counter TODO: these should just take the key, will fix when renaming field
75 76 77 |
# File 'lib/von/config.rb', line 75 def periods_defined_for_counter?(counter) @periods.has_key?(counter.field) end |
#redis ⇒ Object
Returns the Redis connection
57 58 59 |
# File 'lib/von/config.rb', line 57 def redis @redis ||= Redis.new end |
#redis=(arg) ⇒ Object
Set the Redis connection to use
arg - A Redis connection or a Hash of Redis connection options
Returns the Redis client
48 49 50 51 52 53 54 |
# File 'lib/von/config.rb', line 48 def redis=(arg) if arg.is_a? Redis @redis = arg else @redis = Redis.new(arg) end end |