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 +8 -1
- data/lib/tabs/helpers.rb +1 -1
- data/lib/tabs/resolution.rb +5 -0
- data/lib/tabs/resolutionable.rb +8 -6
- data/lib/tabs/resolutions/day.rb +5 -1
- data/lib/tabs/resolutions/hour.rb +5 -1
- data/lib/tabs/resolutions/minute.rb +5 -1
- data/lib/tabs/resolutions/month.rb +5 -1
- data/lib/tabs/resolutions/week.rb +6 -2
- data/lib/tabs/resolutions/year.rb +5 -1
- data/lib/tabs/version.rb +1 -1
- data/spec/lib/tabs/resolution_spec.rb +11 -11
- data/spec/support/custom_resolutions.rb +4 -0
- data/tabs.gemspec +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
![Travis Status](https://api.travis-ci.org/
|
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.
|
data/lib/tabs/helpers.rb
CHANGED
data/lib/tabs/resolution.rb
CHANGED
@@ -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
|
data/lib/tabs/resolutionable.rb
CHANGED
@@ -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
|
6
|
+
raise "Must implement serialize in the concrete resolution module"
|
9
7
|
end
|
10
8
|
|
11
9
|
def deserialize
|
12
|
-
raise
|
10
|
+
raise "Must implement deserialize in the concrete resolution module"
|
13
11
|
end
|
14
12
|
|
15
13
|
def from_seconds
|
16
|
-
raise
|
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
|
22
|
+
raise "Must implement normalize in the concrete resolution module"
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
data/lib/tabs/resolutions/day.rb
CHANGED
data/lib/tabs/version.rb
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
require
|
2
|
-
require File.expand_path(
|
1
|
+
require "spec_helper"
|
2
|
+
require File.expand_path("../../../support/custom_resolutions", __FILE__)
|
3
3
|
|
4
4
|
describe Tabs::Resolution do
|
5
|
-
describe
|
6
|
-
it
|
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
|
12
|
-
it
|
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
|
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(
|
21
|
-
expect(Tabs.get_stats(
|
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
|
25
|
-
expect{BadlyFormedResolution.normalize}.to raise_error
|
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
|
data/tabs.gemspec
CHANGED
@@ -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/
|
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.
|
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-
|
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/
|
172
|
+
homepage: https://github.com/devmynd/tabs
|
173
173
|
licenses: []
|
174
174
|
post_install_message: ! 'Tabs v0.8.0 - BREAKING CHANGES:
|
175
175
|
|