tabs 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![Travis Status](https://api.travis-ci.org/thegrubbsian/tabs.png)
1
+ ![Travis Status](https://api.travis-ci.org/devmynd/tabs.png)
2
2
 
3
3
  # Tabs
4
4
 
@@ -226,6 +226,10 @@ module SecondResolution
226
226
  s / 1
227
227
  end
228
228
 
229
+ def add(timestamp, num_of_seconds)
230
+ timestamp + num_of_seconds.seconds
231
+ end
232
+
229
233
  def normalize(ts)
230
234
  Time.utc(ts.year, ts.month, ts.day, ts.hour, ts.min, ts.sec)
231
235
  end
@@ -245,6 +249,9 @@ into an actual DateTime value.
245
249
  *`from_seconds`*: should return the number of periods in the given
246
250
  number of seconds. For example, there are 60 seconds in a minute.
247
251
 
252
+ *`add`*: should add the number of seconds in the given resolution to the
253
+ supplied timestamp.
254
+
248
255
  *`normalize`*: should simply return the first timestamp for the period.
249
256
  For example, the week resolution returns the first hour of the first day
250
257
  of the week.
@@ -7,7 +7,7 @@ module Tabs
7
7
  dt = period.first
8
8
  [].tap do |arr|
9
9
  arr << dt
10
- while (dt = dt + 1.send(resolution)) <= period.last
10
+ while (dt = Tabs::Resolution.add(resolution, dt, 1)) <= period.last
11
11
  arr << dt.utc
12
12
  end
13
13
  end
@@ -1,5 +1,6 @@
1
1
  module Tabs
2
2
  module Resolution
3
+ extend Resolutionable
3
4
  extend self
4
5
 
5
6
  def register(resolution, klass)
@@ -19,6 +20,10 @@ module Tabs
19
20
  resolution_klass(resolution).from_seconds(s)
20
21
  end
21
22
 
23
+ def add(resolution, ts, num)
24
+ resolution_klass(resolution).add(ts, num)
25
+ end
26
+
22
27
  def normalize(resolution, timestamp)
23
28
  resolution_klass(resolution).normalize(timestamp)
24
29
  end
@@ -2,22 +2,24 @@ module Tabs
2
2
  module Resolutionable
3
3
  extend self
4
4
 
5
- class MethodNotImplementedException < Exception; end
6
-
7
5
  def serialize
8
- raise MethodNotImplementedException
6
+ raise "Must implement serialize in the concrete resolution module"
9
7
  end
10
8
 
11
9
  def deserialize
12
- raise MethodNotImplementedException
10
+ raise "Must implement deserialize in the concrete resolution module"
13
11
  end
14
12
 
15
13
  def from_seconds
16
- raise MethodNotImplementedException
14
+ raise "Must implement from_seconds in the concrete resolution module"
15
+ end
16
+
17
+ def add
18
+ raise "Must implement to_seconds in the concrete resolution module"
17
19
  end
18
20
 
19
21
  def normalize
20
- raise MethodNotImplementedException
22
+ raise "Must implement normalize in the concrete resolution module"
21
23
  end
22
24
  end
23
25
  end
@@ -16,7 +16,11 @@ module Tabs
16
16
  end
17
17
 
18
18
  def from_seconds(s)
19
- s / 86400
19
+ s / 1.day
20
+ end
21
+
22
+ def add(ts, num)
23
+ ts + num.days
20
24
  end
21
25
 
22
26
  def normalize(ts)
@@ -16,7 +16,11 @@ module Tabs
16
16
  end
17
17
 
18
18
  def from_seconds(s)
19
- s / 3600
19
+ s / 1.hour
20
+ end
21
+
22
+ def add(ts, num)
23
+ ts + num.hours
20
24
  end
21
25
 
22
26
  def normalize(ts)
@@ -16,7 +16,11 @@ module Tabs
16
16
  end
17
17
 
18
18
  def from_seconds(s)
19
- s / 60.0
19
+ s / 1.minute
20
+ end
21
+
22
+ def add(ts, num)
23
+ ts + num.minutes
20
24
  end
21
25
 
22
26
  def normalize(ts)
@@ -16,7 +16,11 @@ module Tabs
16
16
  end
17
17
 
18
18
  def from_seconds(s)
19
- s / 1728000
19
+ s / 1.month
20
+ end
21
+
22
+ def add(ts, num)
23
+ ts + num.months
20
24
  end
21
25
 
22
26
  def normalize(ts)
@@ -17,8 +17,12 @@ module Tabs
17
17
  self.normalize(dt)
18
18
  end
19
19
 
20
- def from_seconds(s)
21
- s / 432000
20
+ def seconds(s)
21
+ s / 1.week
22
+ end
23
+
24
+ def add(ts, num)
25
+ ts + num.weeks
22
26
  end
23
27
 
24
28
  def normalize(ts)
@@ -16,7 +16,11 @@ module Tabs
16
16
  end
17
17
 
18
18
  def from_seconds(s)
19
- s / 31536000
19
+ s / 1.year
20
+ end
21
+
22
+ def add(ts, num)
23
+ ts + num.years
20
24
  end
21
25
 
22
26
  def normalize(ts)
@@ -1,3 +1,3 @@
1
1
  module Tabs
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -1,28 +1,28 @@
1
- require 'spec_helper'
2
- require File.expand_path('../../../support/custom_resolutions', __FILE__)
1
+ require "spec_helper"
2
+ require File.expand_path("../../../support/custom_resolutions", __FILE__)
3
3
 
4
4
  describe Tabs::Resolution do
5
- describe '#register' do
6
- it 'registers a new resolution' do
5
+ describe "#register" do
6
+ it "registers a new resolution" do
7
7
  Tabs::Resolution.register(:test, Tabs::Resolutions::Minute)
8
8
  expect(Tabs::Resolution.all).to include :test
9
9
  end
10
10
 
11
- context 'with a custom resolution' do
12
- it 'does not return nil' do
11
+ context "with a custom resolution" do
12
+ it "does not return nil" do
13
13
  expect(WellFormedResolution.serialize(Time.now)).to_not be_nil
14
14
  end
15
15
 
16
- it 'gets stats for custom resolution' do
16
+ it "gets stats for custom resolution" do
17
17
  Tabs::Resolution.register(:seconds, WellFormedResolution)
18
18
  Timecop.freeze(Time.now)
19
19
 
20
- Tabs.increment_counter('foo')
21
- expect(Tabs.get_stats('foo', (Time.now - 5.seconds..Time.now), :seconds).values.size).to eq(6)
20
+ Tabs.increment_counter("foo")
21
+ expect(Tabs.get_stats("foo", (Time.now - 5.seconds..Time.now), :seconds).values.size).to eq(6)
22
22
  end
23
23
 
24
- it 'raises an error when method not implemented' do
25
- expect{BadlyFormedResolution.normalize}.to raise_error Tabs::Resolutionable::MethodNotImplementedException
24
+ it "raises an error when method not implemented" do
25
+ expect{BadlyFormedResolution.normalize}.to raise_error
26
26
  end
27
27
  end
28
28
  end
@@ -22,6 +22,10 @@ module WellFormedResolution
22
22
  s / 1
23
23
  end
24
24
 
25
+ def add(ts, num)
26
+ ts + num.seconds
27
+ end
28
+
25
29
  def normalize(ts)
26
30
  Time.utc(ts.year, ts.month, ts.day, ts.hour, ts.min, ts.sec)
27
31
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.email = ["jc.grubbs@devmynd.com"]
12
12
  gem.description = %q{A redis-backed metrics tracker for keeping tabs on pretty much anything ;)}
13
13
  gem.summary = %q{A redis-backed metrics tracker for keeping tabs on pretty much anything ;)}
14
- gem.homepage = "https://github.com/thegrubbsian/tabs"
14
+ gem.homepage = "https://github.com/devmynd/tabs"
15
15
 
16
16
  gem.files = `git ls-files`.split($/)
17
17
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-26 00:00:00.000000000 Z
12
+ date: 2013-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -169,7 +169,7 @@ files:
169
169
  - spec/spec_helper.rb
170
170
  - spec/support/custom_resolutions.rb
171
171
  - tabs.gemspec
172
- homepage: https://github.com/thegrubbsian/tabs
172
+ homepage: https://github.com/devmynd/tabs
173
173
  licenses: []
174
174
  post_install_message: ! 'Tabs v0.8.0 - BREAKING CHANGES:
175
175