Permalink
Browse files

remove unused counter_options from config

  • Loading branch information...
1 parent d427a91 commit 4688f2afa6f10acf5fdf22d4b7b53337e72cb711 @blahed committed Jan 29, 2013
Showing with 16 additions and 30 deletions.
  1. +12 −11 lib/von/config.rb
  2. +0 −5 lib/von/counter.rb
  3. +4 −14 test/config_test.rb
View
@@ -16,8 +16,9 @@ module Config
attr_reader :periods
def init!
- @counter_options = {}
@periods = {}
+ @bests = {}
+ @totals = {}
# all keys are prefixed with this namespace
self.namespace = 'von'
# rescue Redis connection errors
@@ -57,15 +58,11 @@ def redis
# Configure options for given Counter. Configures length of given time period
# and any other options for the Counter
def counter(field, options = {})
- options.each do |key, value|
- if Period::AVAILABLE_PERIODS.include?(key)
- @periods[field.to_sym] ||= {}
- @periods[field.to_sym][key.to_sym] = Period.new(field, key, value)
- options.delete(key)
+ options.each do |option, value|
+ if Period::AVAILABLE_PERIODS.include?(option)
+ set_period(field, option, value)
end
end
-
- @counter_options[field.to_sym] = options
end
# Returns a True if a Period is defined for the
@@ -75,10 +72,14 @@ def period_defined_for?(key, period)
@periods.has_key?(key) && @periods[key].has_key?(period)
end
- # TODO: rename
- def counter_options(field)
- @counter_options[field.to_sym] ||= {}
+ private
+
+ def set_period(field, period, length)
+ field = field.to_sym
+ @periods[field] ||= {}
+ @periods[field][period.to_sym] = Period.new(field, period, length)
end
+
end
end
View
@@ -9,11 +9,6 @@ def initialize(field)
@field = field.to_sym
end
- # Returns options specified in config for this Counter
- def options
- @options ||= Von.config.counter_options(@field)
- end
-
# Returns the Redis hash key used for storing counts for this Counter
def hash_key
@hash_key ||= "#{Von.config.namespace}:counters:#{@field}"
View
@@ -18,24 +18,14 @@
@config.namespace.must_equal 'something'
end
- it 'stores counter options per key and retrieves them' do
- options = { :monthly => 3, :total => false }
-
- @config.counter 'bar', options
-
- @config.namespace.must_equal 'von'
- @config.counter_options('bar').must_equal options
- end
-
- it "allows config options to be updated via configure" do
- options = { :monthly => 3, :total => false }
-
+ it "allows periods to be set via counter method" do
Von.configure do |config|
- config.counter 'bar', options
+ config.counter 'bar', :monthly => 3, :daily => 6
end
Von.config.namespace.must_equal 'von'
- Von.config.counter_options('bar').must_equal options
+ Von.config.periods[:bar].has_key?(:monthly).must_equal true
+ Von.config.periods[:bar][:monthly].length.must_equal 3
end
end

0 comments on commit 4688f2a

Please sign in to comment.