Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rework the way counter options are set/stored

  • Loading branch information...
commit c351df443f2685a7342b00babb02db01c41a7ce4 1 parent a7d55f0
@blahed authored
Showing with 17 additions and 9 deletions.
  1. +12 −7 lib/von/config.rb
  2. +5 −2 test/config_test.rb
View
19 lib/von/config.rb
@@ -66,18 +66,23 @@ def counter(field, options = {})
end
end
- # Returns a True if a Period is defined for the
- # given period identifier and the period has a length
- # False if not
- def period_defined_for?(key, period)
- @periods.has_key?(key) && @periods[key].has_key?(period)
+ # Returns a True if a period is defined for the
+ # given Counter
+ def periods_defined_for_counter?(counter)
+ @periods.has_key?(counter.field)
+ end
+
+ # Returns a True if a best is defined for the
+ # given counter
+ def bests_defined_for_counter?(counter)
+ @bests.has_key?(counter.field)
end
private
def set_period(field, period, length)
- @periods[field] ||= {}
- @periods[field][period.to_sym] = Period.new(period, length)
+ @periods[field] ||= []
+ @periods[field] << Period.new(period, length)
end
def set_best(field, time_unit)
View
7 test/config_test.rb
@@ -23,8 +23,11 @@
config.counter 'bar', :monthly => 3, :daily => 6
end
- Von.config.periods[:bar].has_key?(:monthly).must_equal true
- Von.config.periods[:bar][:monthly].length.must_equal 3
+ Von.config.periods[:bar].length.must_equal 2
+ Von.config.periods[:bar].first.period.must_equal :monthly
+ Von.config.periods[:bar].first.length.must_equal 3
+ Von.config.periods[:bar].last.period.must_equal :daily
+ Von.config.periods[:bar].last.length.must_equal 6
end
it "allows bests to be set via counter method" do
Please sign in to comment.
Something went wrong with that request. Please try again.