active_redis_stats 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d45f723d18b29a6e875ecc5583c18c6d1ee0ba0d59c0ba67bc8eb2381a5a14a
4
- data.tar.gz: 42d832e0aed98ef66e2f761556d045234eca8dded75c8740871d62f46e440107
3
+ metadata.gz: 646cf926b9891a817ab1fdbb777bc0279fc5f633de41af5819bdfe907c13fcfe
4
+ data.tar.gz: 462068744e79fddb300a5e67368afb2cf2248ef967ffbd966d3c14970ba66408
5
5
  SHA512:
6
- metadata.gz: 4f40f595689a0105b033a16588b08d53d10e7de7cbb6d7f6b845bf92e969bde6495b9465f2211e2170af154af9d2f1c0a8097cdc4c9485b9677c508185508700
7
- data.tar.gz: ec2def78c6cd40f15b17a905f3fe51efb5ebc18d3555d969bc15423f0e635ac830f412a491cae8ab11b1e781a69a513f1699472ca8190776fef37e1670d8475e
6
+ metadata.gz: a9bd6a89c385cd96e1a65c47806aea83c92b9428a9aadf1044f5123248b1bcbe2dbb9a6a5fdfc0fe60bc2667ab2a272ea57d9902fe7f30d4c68961c6461b33d5
7
+ data.tar.gz: 72dbbefb90f5a6574499cad4698611cec300d6bb0a5413abe37a7ed2b600f312a71f93af12f73ca515f5f2e3187e0dc7438f3fb66ed041693dc1fe30027ea7a0
@@ -21,85 +21,87 @@ module ActiveRedisStats
21
21
  inf: nil # never
22
22
  }.freeze
23
23
 
24
- def self.interval_key(format, time: TIME)
25
- format = format.to_sym
26
- return "#{format}:#{format}" if format == :inf
24
+ class << self
25
+ def interval_key(format, time: TIME)
26
+ format = format.to_sym
27
+ return "#{format}:#{format}" if format == :inf
27
28
 
28
- interval = time.format(FORMATS[format])
29
- "#{format}:#{interval}"
30
- end
29
+ interval = time.format(FORMATS[format])
30
+ "#{format}:#{interval}"
31
+ end
31
32
 
32
- def self.hour_key(offset: 0)
33
- interval_key(:day, time: offset.minutes.ago(TIME))
34
- end
33
+ def hour_key(offset: 0)
34
+ interval_key(:day, time: offset.minutes.ago(TIME))
35
+ end
35
36
 
36
- def self.hour_keys(offset: 0)
37
- adj = (30 * offset)
38
- max = 29 + adj
39
- min = 0 + adj
37
+ def hour_keys(offset: 0)
38
+ adj = (30 * offset)
39
+ max = 29 + adj
40
+ min = 0 + adj
40
41
 
41
- max.downto(min).collect do |num|
42
- interval_key(:hour, time: num.minutes.ago(TIME))
42
+ max.downto(min).collect do |num|
43
+ interval_key(:hour, time: num.minutes.ago(TIME))
44
+ end
43
45
  end
44
- end
45
46
 
46
- def self.day_key(offset: 0)
47
- interval_key(:month, time: offset.days.ago(TIME))
48
- end
47
+ def day_key(offset: 0)
48
+ interval_key(:month, time: offset.days.ago(TIME))
49
+ end
49
50
 
50
- def self.day_keys(offset: 0)
51
- boy = offset.days.ago(TIME).beginning_of_day
51
+ def day_keys(offset: 0)
52
+ boy = offset.days.ago(TIME).beginning_of_day
52
53
 
53
- 0.upto(23).collect do |num|
54
- interval_key(:day, time: num.hours.from_now(boy))
54
+ 0.upto(23).collect do |num|
55
+ interval_key(:day, time: num.hours.from_now(boy))
56
+ end
55
57
  end
56
- end
57
58
 
58
- def self.month_key(offset: 0)
59
- interval_key(:year, time: offset.months.ago(TIME))
60
- end
59
+ def month_key(offset: 0)
60
+ interval_key(:year, time: offset.months.ago(TIME))
61
+ end
61
62
 
62
- def self.month_keys(offset: 0)
63
- boy = offset.months.ago(TIME).beginning_of_month
64
- max = boy.end_of_month.day - 1
63
+ def month_keys(offset: 0)
64
+ boy = offset.months.ago(TIME).beginning_of_month
65
+ max = boy.end_of_month.day - 1
65
66
 
66
- 0.upto(max).collect do |num|
67
- interval_key(:month, time: num.days.from_now(boy))
67
+ 0.upto(max).collect do |num|
68
+ interval_key(:month, time: num.days.from_now(boy))
69
+ end
68
70
  end
69
- end
70
71
 
71
- def self.year_key(offset: 0)
72
- interval_key(:all, time: offset.years.ago(TIME))
73
- end
72
+ def year_key(offset: 0)
73
+ interval_key(:all, time: offset.years.ago(TIME))
74
+ end
74
75
 
75
- def self.year_keys(offset: 0)
76
- boy = offset.years.ago(TIME).beginning_of_year
76
+ def year_keys(offset: 0)
77
+ boy = offset.years.ago(TIME).beginning_of_year
77
78
 
78
- 0.upto(11).collect do |num|
79
- interval_key(:year, time: num.months.from_now(boy))
79
+ 0.upto(11).collect do |num|
80
+ interval_key(:year, time: num.months.from_now(boy))
81
+ end
80
82
  end
81
- end
82
83
 
83
- # rubocop:disable Lint/UnusedMethodArgument
84
- def self.all_key(offset: 0)
85
- interval_key(:inf)
86
- end
87
- # rubocop:enable Lint/UnusedMethodArgument
84
+ # rubocop:disable Lint/UnusedMethodArgument
85
+ def all_key(offset: 0)
86
+ interval_key(:inf)
87
+ end
88
+ # rubocop:enable Lint/UnusedMethodArgument
88
89
 
89
- def self.all_keys(offset: 0)
90
- max = 9 + offset
91
- min = 0 + offset
90
+ def all_keys(offset: 0)
91
+ max = 9 + offset
92
+ min = 0 + offset
92
93
 
93
- max.downto(min).collect do |num|
94
- interval_key(:all, time: num.years.ago(TIME))
94
+ max.downto(min).collect do |num|
95
+ interval_key(:all, time: num.years.ago(TIME))
96
+ end
95
97
  end
96
- end
97
98
 
98
- def self.expiration(key, seconds)
99
- return if seconds.nil?
99
+ def expiration(key, seconds)
100
+ return if seconds.nil?
100
101
 
101
- ActiveRedisDB::Key
102
- .expire(primary_key(key), seconds)
102
+ ActiveRedisDB::Key
103
+ .expire(primary_key(key), seconds)
104
+ end
103
105
  end
104
106
 
105
107
  end
@@ -4,8 +4,10 @@ module ActiveRedisStats
4
4
  module Count
5
5
  class Base < ActiveRedisStats::Base
6
6
 
7
- def self.primary_key(key)
8
- "ars:count:#{key}"
7
+ class << self
8
+ def primary_key(key)
9
+ "ars:count:#{key}"
10
+ end
9
11
  end
10
12
 
11
13
  end
@@ -4,15 +4,17 @@ module ActiveRedisStats
4
4
  module Count
5
5
  class Get < ActiveRedisStats::Count::Base
6
6
 
7
- def self.total(key)
8
- ActiveRedisDB::String
9
- .evaluate
10
- .find(primary_key(key)) || 0
11
- end
7
+ class << self
8
+ def total(key)
9
+ ActiveRedisDB::String
10
+ .evaluate
11
+ .find(primary_key(key)) || 0
12
+ end
12
13
 
13
- def self.total_intervals(key, format: :month, offset: 0)
14
- keys = send("#{format}_keys", offset: offset)
15
- keys.collect { |k| total("#{key}:#{k}") }
14
+ def total_intervals(key, format: :month, offset: 0)
15
+ keys = send("#{format}_keys", offset: offset)
16
+ keys.collect { |k| total("#{key}:#{k}") }
17
+ end
16
18
  end
17
19
 
18
20
  end
@@ -3,8 +3,8 @@
3
3
  module ActiveRedisStats
4
4
  module Count
5
5
  class Set < ActiveRedisStats::Count::Base
6
- class << self
7
6
 
7
+ class << self
8
8
  %i[decrement increment].each do |meth|
9
9
  define_method(meth) do |key, by: 1|
10
10
  ActiveRedisDB::String
@@ -20,8 +20,8 @@ module ActiveRedisStats
20
20
  end
21
21
  end
22
22
  end
23
-
24
23
  end
24
+
25
25
  end
26
26
  end
27
27
  end
@@ -4,8 +4,10 @@ module ActiveRedisStats
4
4
  module Rank
5
5
  class Base < ActiveRedisStats::Base
6
6
 
7
- def self.primary_key(key)
8
- "ars:rank:#{key}"
7
+ class << self
8
+ def primary_key(key)
9
+ "ars:rank:#{key}"
10
+ end
9
11
  end
10
12
 
11
13
  end
@@ -6,50 +6,52 @@ module ActiveRedisStats
6
6
 
7
7
  LIMIT ||= 100
8
8
 
9
- def self.all(key, with_scores: false)
10
- ActiveRedisDB::SortedSet
11
- .evaluate
12
- .all_reverse(primary_key(key), with_scores: with_scores) || []
13
- end
14
-
15
- def self.all_intervals(key, with_scores: false, format: :month, offset: 0)
16
- ikey = send("#{format}_key", offset: offset)
17
- all("#{key}:#{ikey}", with_scores: with_scores)
18
- end
19
-
20
- def self.between(key, with_scores: false, from:, to:)
21
- ActiveRedisDB::SortedSet
22
- .evaluate
23
- .between_reverse(primary_key(key), from, to, with_scores: with_scores) || []
24
- end
25
-
26
- # rubocop:disable Metrics/ParameterLists
27
- def self.between_intervals(key, with_scores: false, from:, to:, format: :month, offset: 0)
28
- ikey = send("#{format}_key", offset: offset)
29
- between("#{key}:#{ikey}", with_scores: with_scores, from: from, to: to)
30
- end
31
- # rubocop:enable Metrics/ParameterLists
32
-
33
- def self.bottom(key, with_scores: false, limit: LIMIT)
34
- ActiveRedisDB::SortedSet
35
- .evaluate
36
- .between(primary_key(key), 1, limit, with_scores: with_scores) || []
37
- end
38
-
39
- def self.bottom_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
40
- ikey = send("#{format}_key", offset: offset)
41
- bottom("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
42
- end
43
-
44
- def self.top(key, with_scores: false, limit: LIMIT)
45
- ActiveRedisDB::SortedSet
46
- .evaluate
47
- .between_reverse(primary_key(key), 1, limit, with_scores: with_scores) || []
48
- end
49
-
50
- def self.top_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
51
- ikey = send("#{format}_key", offset: offset)
52
- top("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
9
+ class << self
10
+ def all(key, with_scores: false)
11
+ ActiveRedisDB::SortedSet
12
+ .evaluate
13
+ .all_reverse(primary_key(key), with_scores: with_scores) || []
14
+ end
15
+
16
+ def all_intervals(key, with_scores: false, format: :month, offset: 0)
17
+ ikey = send("#{format}_key", offset: offset)
18
+ all("#{key}:#{ikey}", with_scores: with_scores)
19
+ end
20
+
21
+ def between(key, with_scores: false, from:, to:)
22
+ ActiveRedisDB::SortedSet
23
+ .evaluate
24
+ .between_reverse(primary_key(key), from, to, with_scores: with_scores) || []
25
+ end
26
+
27
+ # rubocop:disable Metrics/ParameterLists
28
+ def between_intervals(key, with_scores: false, from:, to:, format: :month, offset: 0)
29
+ ikey = send("#{format}_key", offset: offset)
30
+ between("#{key}:#{ikey}", with_scores: with_scores, from: from, to: to)
31
+ end
32
+ # rubocop:enable Metrics/ParameterLists
33
+
34
+ def bottom(key, with_scores: false, limit: LIMIT)
35
+ ActiveRedisDB::SortedSet
36
+ .evaluate
37
+ .between(primary_key(key), 1, limit, with_scores: with_scores) || []
38
+ end
39
+
40
+ def bottom_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
41
+ ikey = send("#{format}_key", offset: offset)
42
+ bottom("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
43
+ end
44
+
45
+ def top(key, with_scores: false, limit: LIMIT)
46
+ ActiveRedisDB::SortedSet
47
+ .evaluate
48
+ .between_reverse(primary_key(key), 1, limit, with_scores: with_scores) || []
49
+ end
50
+
51
+ def top_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
52
+ ikey = send("#{format}_key", offset: offset)
53
+ top("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
54
+ end
53
55
  end
54
56
 
55
57
  end
@@ -3,8 +3,8 @@
3
3
  module ActiveRedisStats
4
4
  module Rank
5
5
  class Set < ActiveRedisStats::Rank::Base
6
- class << self
7
6
 
7
+ class << self
8
8
  %i[decrement increment].each do |meth|
9
9
  define_method(meth) do |key, val, by: 1|
10
10
  ActiveRedisDB::SortedSet
@@ -20,8 +20,8 @@ module ActiveRedisStats
20
20
  end
21
21
  end
22
22
  end
23
-
24
23
  end
24
+
25
25
  end
26
26
  end
27
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRedisStats
4
- VERSION ||= '0.1.0'
4
+ VERSION ||= '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_redis_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-01 00:00:00.000000000 Z
11
+ date: 2018-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: active_object