Skip to content

Commit

Permalink
rework the way counter options are set/stored
Browse files Browse the repository at this point in the history
  • Loading branch information
blahed committed Jan 30, 2013
1 parent a7d55f0 commit c351df4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
19 changes: 12 additions & 7 deletions lib/von/config.rb
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions test/config_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit c351df4

Please sign in to comment.