Module: Von

Defined in:
lib/von.rb,
lib/von/config.rb,
lib/von/period.rb,
lib/von/counter.rb,
lib/von/version.rb,
lib/von/counters/best.rb,
lib/von/counters/total.rb,
lib/von/counters/period.rb,
lib/von/counters/current.rb,
lib/von/counters/commands.rb

Defined Under Namespace

Modules: Config, Counters Classes: Counter, Period

Constant Summary collapse

PARENT_REGEX =
/:?[^:]+\z/
VERSION =
'0.2.0'

Class Method Summary collapse

Class Method Details

.configObject



21
22
23
# File 'lib/von.rb', line 21

def self.config
  Config
end

.configure {|config| ... } ⇒ Object

Yields:



25
26
27
# File 'lib/von.rb', line 25

def self.configure
  yield(config)
end

.connectionObject



17
18
19
# File 'lib/von.rb', line 17

def self.connection
  @connection ||= config.redis
end

.count(field) ⇒ Object



65
66
67
68
69
# File 'lib/von.rb', line 65

def self.count(field)
  Counter.new(field)
rescue Redis::BaseError => e
  raise e if config.raise_connection_errors
end

.increment(field) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/von.rb', line 29

def self.increment(field)
  parents = field.to_s.sub(PARENT_REGEX, '')
  total   = increment_counts_for(field)

  until parents.empty? do
    increment_counts_for(parents)
    parents.sub!(PARENT_REGEX, '')
  end

  total
rescue Redis::BaseError => e
  raise e if config.raise_connection_errors
end

.increment_counts_for(field) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/von.rb', line 43

def self.increment_counts_for(field)
  counter = Counters::Total.new(field)
  total   = counter.increment

  if config.periods_defined_for_counter?(counter)
    periods = config.periods[counter.field]
    Counters::Period.new(counter.field, periods).increment
  end

  if config.bests_defined_for_counter?(counter)
    periods = config.bests[counter.field]
    Counters::Best.new(counter.field, periods).increment
  end

  if config.currents_defined_for_counter?(counter)
    periods = config.currents[counter.field]
    Counters::Current.new(counter.field, periods).increment
  end

  total
end