redis-objects-daily-counter 0.2.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +23 -20
- data/.gem_comet.yml +1 -1
- data/.github/dependabot.yml +19 -0
- data/.rubocop.yml +5 -4
- data/.rubocop_todo.yml +3 -19
- data/CHANGELOG.md +106 -9
- data/Dockerfile +1 -1
- data/Gemfile +3 -3
- data/Gemfile.lock +32 -29
- data/README.md +125 -25
- data/Rakefile +4 -1
- data/bin/console +2 -3
- data/lib/redis/base_counter_object.rb +11 -38
- data/lib/redis/base_hash_key_object.rb +40 -0
- data/lib/redis/base_set_object.rb +28 -0
- data/lib/redis/objects/{daily-counter → periodical}/version.rb +2 -4
- data/lib/redis/objects/periodical_counters.rb +40 -0
- data/lib/redis/objects/periodical_hashes.rb +50 -0
- data/lib/redis/objects/periodical_sets.rb +50 -0
- data/lib/redis/periodical_counter.rb +15 -0
- data/lib/redis/periodical_hash_key.rb +15 -0
- data/lib/redis/periodical_set.rb +15 -0
- data/lib/redis/recurring_at_intervals/annual.rb +18 -0
- data/lib/redis/recurring_at_intervals/daily.rb +18 -0
- data/lib/redis/recurring_at_intervals/hourly.rb +18 -0
- data/lib/redis/recurring_at_intervals/minutely.rb +18 -0
- data/lib/redis/recurring_at_intervals/monthly.rb +18 -0
- data/lib/redis/recurring_at_intervals/weekly.rb +18 -0
- data/lib/redis/recurring_at_intervals.rb +79 -0
- data/lib/redis-objects-periodical.rb +36 -0
- data/redis-objects-daily-counter.gemspec +5 -4
- data/redis-objects-periodical.gemspec +36 -0
- metadata +26 -19
- data/lib/redis/annual_counter.rb +0 -18
- data/lib/redis/daily_counter.rb +0 -18
- data/lib/redis/hourly_counter.rb +0 -26
- data/lib/redis/minutely_counter.rb +0 -26
- data/lib/redis/monthly_counter.rb +0 -18
- data/lib/redis/objects/annual_counters.rb +0 -41
- data/lib/redis/objects/daily_counters.rb +0 -41
- data/lib/redis/objects/hourly_counters.rb +0 -41
- data/lib/redis/objects/minutely_counters.rb +0 -41
- data/lib/redis/objects/monthly_counters.rb +0 -41
- data/lib/redis/objects/weekly_counters.rb +0 -41
- data/lib/redis/weekly_counter.rb +0 -18
- data/lib/redis-objects-daily-counter.rb +0 -37
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
module RecurringAtIntervals
|
5
|
+
module Weekly
|
6
|
+
private
|
7
|
+
|
8
|
+
def redis_daily_field_key(date_or_time)
|
9
|
+
date_key = date_or_time.strftime('%YW%W')
|
10
|
+
[original_key, date_key].flatten.join(':')
|
11
|
+
end
|
12
|
+
|
13
|
+
def next_key(date, length = 1)
|
14
|
+
date + 7 * length
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
module RecurringAtIntervals
|
5
|
+
def initialize(key, *args)
|
6
|
+
@original_key = key
|
7
|
+
super(redis_daily_field_key(current_time), *args)
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :original_key
|
11
|
+
|
12
|
+
def [](date_or_time, length = nil)
|
13
|
+
if date_or_time.is_a? Range
|
14
|
+
range(date_or_time.first, date_or_time.max)
|
15
|
+
elsif length
|
16
|
+
case length <=> 0
|
17
|
+
when 1 then range(date_or_time, next_key(date_or_time, length - 1))
|
18
|
+
when 0 then empty_value
|
19
|
+
when -1 then nil # Ruby does this (a bit weird)
|
20
|
+
end
|
21
|
+
else
|
22
|
+
get_value_from_redis(redis_daily_field_key(date_or_time))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
alias slice []
|
26
|
+
|
27
|
+
def delete_at(date_or_time)
|
28
|
+
delete_from_redis(redis_daily_field_key(date_or_time))
|
29
|
+
end
|
30
|
+
|
31
|
+
def range(start_date_or_time, end_date_or_time)
|
32
|
+
keys = []
|
33
|
+
date_or_time = start_date_or_time
|
34
|
+
|
35
|
+
loop do
|
36
|
+
break if date_or_time > end_date_or_time
|
37
|
+
|
38
|
+
keys << redis_daily_field_key(date_or_time)
|
39
|
+
date_or_time = next_key(date_or_time)
|
40
|
+
end
|
41
|
+
|
42
|
+
get_values_from_redis(keys)
|
43
|
+
end
|
44
|
+
|
45
|
+
def at(date_or_time)
|
46
|
+
get_redis_object(redis_daily_field_key(date_or_time))
|
47
|
+
end
|
48
|
+
|
49
|
+
def current_time
|
50
|
+
@current_time ||= Time.respond_to?(:current) ? Time.current : Time.now
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def get_redis_object(_key)
|
56
|
+
raise 'not implemented'
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_value_from_redis(_key)
|
60
|
+
raise 'not implemented'
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_values_from_redis(_keys)
|
64
|
+
raise 'not implemented'
|
65
|
+
end
|
66
|
+
|
67
|
+
def delete_from_redis(_key)
|
68
|
+
raise 'not implemented'
|
69
|
+
end
|
70
|
+
|
71
|
+
def redis_daily_field_key(_date_or_time)
|
72
|
+
raise 'not implemented'
|
73
|
+
end
|
74
|
+
|
75
|
+
def next_key(_date, _length = 1)
|
76
|
+
raise 'not implemented'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'redis-objects'
|
4
|
+
|
5
|
+
class Redis
|
6
|
+
PERIODICALS = %w[daily weekly monthly annual hourly minutely].freeze
|
7
|
+
|
8
|
+
PERIODICALS.each do |periodical|
|
9
|
+
autoload :"#{periodical.capitalize}Counter", 'redis/periodical_counter'
|
10
|
+
autoload :"#{periodical.capitalize}HashKey", 'redis/periodical_hash_key'
|
11
|
+
autoload :"#{periodical.capitalize}Set", 'redis/periodical_set'
|
12
|
+
end
|
13
|
+
|
14
|
+
module Objects
|
15
|
+
PERIODICALS.each do |periodical|
|
16
|
+
autoload :"#{periodical.capitalize}Counters", 'redis/objects/periodical_counters'
|
17
|
+
autoload :"#{periodical.capitalize}Hashes", 'redis/objects/periodical_hashes'
|
18
|
+
autoload :"#{periodical.capitalize}Sets", 'redis/objects/periodical_sets'
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
alias original_included included
|
23
|
+
|
24
|
+
def included(klass)
|
25
|
+
original_included(klass)
|
26
|
+
|
27
|
+
# Pull in each object type
|
28
|
+
PERIODICALS.each do |periodical|
|
29
|
+
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Counters")
|
30
|
+
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Hashes")
|
31
|
+
klass.send :include, const_get("Redis::Objects::#{periodical.capitalize}Sets")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -1,15 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'lib/redis/objects/daily-counter/version'
|
4
|
-
|
5
3
|
Gem::Specification.new do |spec|
|
6
4
|
spec.name = 'redis-objects-daily-counter'
|
7
|
-
spec.version =
|
5
|
+
spec.version = '0.4.1'
|
8
6
|
spec.authors = ['ryz310']
|
9
7
|
spec.email = ['ryz310@gmail.com']
|
10
8
|
|
11
9
|
spec.summary = 'Daily counter within Redis::Objects'
|
12
10
|
spec.description = 'Daily counter within Redis::Objects. Works with any class or ORM.'
|
11
|
+
spec.post_install_message = 'The redis-objects-daily-counter gem has been deprecated and has '\
|
12
|
+
'been replaced by redis-objects-periodical. Please switch to '\
|
13
|
+
'redis-objects-periodical as soon as possible.'
|
13
14
|
spec.homepage = 'https://github.com/ryz310/redis-objects-daily-counter'
|
14
15
|
spec.license = 'MIT'
|
15
16
|
|
@@ -26,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
28
|
spec.require_paths = ['lib']
|
28
29
|
|
29
|
-
spec.required_ruby_version = '>= 2.
|
30
|
+
spec.required_ruby_version = '>= 2.7.0'
|
30
31
|
|
31
32
|
spec.add_dependency 'redis-objects'
|
32
33
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/redis/objects/periodical/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'redis-objects-periodical'
|
7
|
+
spec.version = Redis::Objects::Periodical::VERSION
|
8
|
+
spec.authors = ['ryz310']
|
9
|
+
spec.email = ['ryz310@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Extends Redis::Objects as periodical.'
|
12
|
+
spec.description = 'Extends Redis::Objects to switch automatically the save destination ' \
|
13
|
+
'within Redis on changing dates.'
|
14
|
+
spec.homepage = 'https://github.com/ryz310/redis-objects-periodical'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ryz310/redis-objects-periodical'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ryz310/redis-objects-periodical/blob/master/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.required_ruby_version = '>= 2.7.0'
|
31
|
+
|
32
|
+
spec.add_dependency 'redis-objects'
|
33
|
+
|
34
|
+
# For more information and examples about making a new gem, checkout our
|
35
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-objects-daily-counter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ryz310
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis-objects
|
@@ -33,6 +33,7 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- ".circleci/config.yml"
|
35
35
|
- ".gem_comet.yml"
|
36
|
+
- ".github/dependabot.yml"
|
36
37
|
- ".gitignore"
|
37
38
|
- ".rspec"
|
38
39
|
- ".rubocop.yml"
|
@@ -48,22 +49,26 @@ files:
|
|
48
49
|
- bin/console
|
49
50
|
- bin/setup
|
50
51
|
- docker-compose.yml
|
51
|
-
- lib/redis-objects-
|
52
|
-
- lib/redis/annual_counter.rb
|
52
|
+
- lib/redis-objects-periodical.rb
|
53
53
|
- lib/redis/base_counter_object.rb
|
54
|
-
- lib/redis/
|
55
|
-
- lib/redis/
|
56
|
-
- lib/redis/
|
57
|
-
- lib/redis/
|
58
|
-
- lib/redis/objects/
|
59
|
-
- lib/redis/objects/
|
60
|
-
- lib/redis/
|
61
|
-
- lib/redis/
|
62
|
-
- lib/redis/
|
63
|
-
- lib/redis/
|
64
|
-
- lib/redis/
|
65
|
-
- lib/redis/
|
54
|
+
- lib/redis/base_hash_key_object.rb
|
55
|
+
- lib/redis/base_set_object.rb
|
56
|
+
- lib/redis/objects/periodical/version.rb
|
57
|
+
- lib/redis/objects/periodical_counters.rb
|
58
|
+
- lib/redis/objects/periodical_hashes.rb
|
59
|
+
- lib/redis/objects/periodical_sets.rb
|
60
|
+
- lib/redis/periodical_counter.rb
|
61
|
+
- lib/redis/periodical_hash_key.rb
|
62
|
+
- lib/redis/periodical_set.rb
|
63
|
+
- lib/redis/recurring_at_intervals.rb
|
64
|
+
- lib/redis/recurring_at_intervals/annual.rb
|
65
|
+
- lib/redis/recurring_at_intervals/daily.rb
|
66
|
+
- lib/redis/recurring_at_intervals/hourly.rb
|
67
|
+
- lib/redis/recurring_at_intervals/minutely.rb
|
68
|
+
- lib/redis/recurring_at_intervals/monthly.rb
|
69
|
+
- lib/redis/recurring_at_intervals/weekly.rb
|
66
70
|
- redis-objects-daily-counter.gemspec
|
71
|
+
- redis-objects-periodical.gemspec
|
67
72
|
homepage: https://github.com/ryz310/redis-objects-daily-counter
|
68
73
|
licenses:
|
69
74
|
- MIT
|
@@ -71,7 +76,9 @@ metadata:
|
|
71
76
|
homepage_uri: https://github.com/ryz310/redis-objects-daily-counter
|
72
77
|
source_code_uri: https://github.com/ryz310/redis-objects-daily-counter
|
73
78
|
changelog_uri: https://github.com/ryz310/redis-objects-daily-counter/blob/master/CHANGELOG.md
|
74
|
-
post_install_message:
|
79
|
+
post_install_message: The redis-objects-daily-counter gem has been deprecated and
|
80
|
+
has been replaced by redis-objects-periodical. Please switch to redis-objects-periodical
|
81
|
+
as soon as possible.
|
75
82
|
rdoc_options: []
|
76
83
|
require_paths:
|
77
84
|
- lib
|
@@ -79,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
86
|
requirements:
|
80
87
|
- - ">="
|
81
88
|
- !ruby/object:Gem::Version
|
82
|
-
version: 2.
|
89
|
+
version: 2.7.0
|
83
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
91
|
requirements:
|
85
92
|
- - ">="
|
86
93
|
- !ruby/object:Gem::Version
|
87
94
|
version: '0'
|
88
95
|
requirements: []
|
89
|
-
rubygems_version: 3.
|
96
|
+
rubygems_version: 3.3.7
|
90
97
|
signing_key:
|
91
98
|
specification_version: 4
|
92
99
|
summary: Daily counter within Redis::Objects
|
data/lib/redis/annual_counter.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/base_counter_object"
|
4
|
-
|
5
|
-
class Redis
|
6
|
-
class AnnualCounter < BaseCounterObject
|
7
|
-
private
|
8
|
-
|
9
|
-
def redis_daily_field_key(date_or_time)
|
10
|
-
date_key = date_or_time.strftime('%Y')
|
11
|
-
[original_key, date_key].flatten.join(':')
|
12
|
-
end
|
13
|
-
|
14
|
-
def next_key(date, length)
|
15
|
-
date.next_year(length - 1)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/redis/daily_counter.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/base_counter_object"
|
4
|
-
|
5
|
-
class Redis
|
6
|
-
class DailyCounter < BaseCounterObject
|
7
|
-
private
|
8
|
-
|
9
|
-
def redis_daily_field_key(date_or_time)
|
10
|
-
date_key = date_or_time.strftime('%Y-%m-%d')
|
11
|
-
[original_key, date_key].flatten.join(':')
|
12
|
-
end
|
13
|
-
|
14
|
-
def next_key(date, length)
|
15
|
-
date + length - 1
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/lib/redis/hourly_counter.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/base_counter_object"
|
4
|
-
|
5
|
-
class Redis
|
6
|
-
class HourlyCounter < BaseCounterObject
|
7
|
-
def range(start_time, end_time)
|
8
|
-
keys =
|
9
|
-
(start_time.to_i..end_time.to_i)
|
10
|
-
.step(3600)
|
11
|
-
.map { |integer| redis_daily_field_key(Time.at(integer)) }
|
12
|
-
redis.mget(*keys).map(&:to_i)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def redis_daily_field_key(time)
|
18
|
-
time_key = time.strftime('%Y-%m-%dT%H')
|
19
|
-
[original_key, time_key].flatten.join(':')
|
20
|
-
end
|
21
|
-
|
22
|
-
def next_key(time, length)
|
23
|
-
time + 3600 * (length - 1)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/base_counter_object"
|
4
|
-
|
5
|
-
class Redis
|
6
|
-
class MinutelyCounter < BaseCounterObject
|
7
|
-
def range(start_time, end_time)
|
8
|
-
keys =
|
9
|
-
(start_time.to_i..end_time.to_i)
|
10
|
-
.step(60)
|
11
|
-
.map { |integer| redis_daily_field_key(Time.at(integer)) }
|
12
|
-
redis.mget(*keys).map(&:to_i)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def redis_daily_field_key(time)
|
18
|
-
time_key = time.strftime('%Y-%m-%dT%H:%M')
|
19
|
-
[original_key, time_key].flatten.join(':')
|
20
|
-
end
|
21
|
-
|
22
|
-
def next_key(time, length)
|
23
|
-
time + 60 * (length - 1)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/base_counter_object"
|
4
|
-
|
5
|
-
class Redis
|
6
|
-
class MonthlyCounter < BaseCounterObject
|
7
|
-
private
|
8
|
-
|
9
|
-
def redis_daily_field_key(date_or_time)
|
10
|
-
date_key = date_or_time.strftime('%Y-%m')
|
11
|
-
[original_key, date_key].flatten.join(':')
|
12
|
-
end
|
13
|
-
|
14
|
-
def next_key(date, length)
|
15
|
-
date.next_month(length - 1)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/annual_counter'
|
4
|
-
class Redis
|
5
|
-
module Objects
|
6
|
-
module AnnualCounters
|
7
|
-
class << self
|
8
|
-
def included(klass)
|
9
|
-
klass.extend ClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def annual_counter(name, options = {}) # rubocop:disable Metrics/MethodLength
|
15
|
-
options[:start] ||= 0
|
16
|
-
options[:type] ||= (options[:start]).zero? ? :increment : :decrement
|
17
|
-
redis_objects[name.to_sym] = options.merge(type: :counter)
|
18
|
-
|
19
|
-
mod = Module.new do
|
20
|
-
define_method(name) do
|
21
|
-
Redis::AnnualCounter.new(
|
22
|
-
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if options[:global]
|
28
|
-
extend mod
|
29
|
-
|
30
|
-
# dispatch to class methods
|
31
|
-
define_method(name) do
|
32
|
-
self.class.public_send(name)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
include mod
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/daily_counter'
|
4
|
-
class Redis
|
5
|
-
module Objects
|
6
|
-
module DailyCounters
|
7
|
-
class << self
|
8
|
-
def included(klass)
|
9
|
-
klass.extend ClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def daily_counter(name, options = {}) # rubocop:disable Metrics/MethodLength
|
15
|
-
options[:start] ||= 0
|
16
|
-
options[:type] ||= (options[:start]).zero? ? :increment : :decrement
|
17
|
-
redis_objects[name.to_sym] = options.merge(type: :counter)
|
18
|
-
|
19
|
-
mod = Module.new do
|
20
|
-
define_method(name) do
|
21
|
-
Redis::DailyCounter.new(
|
22
|
-
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if options[:global]
|
28
|
-
extend mod
|
29
|
-
|
30
|
-
# dispatch to class methods
|
31
|
-
define_method(name) do
|
32
|
-
self.class.public_send(name)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
include mod
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/hourly_counter'
|
4
|
-
class Redis
|
5
|
-
module Objects
|
6
|
-
module HourlyCounters
|
7
|
-
class << self
|
8
|
-
def included(klass)
|
9
|
-
klass.extend ClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def hourly_counter(name, options = {}) # rubocop:disable Metrics/MethodLength
|
15
|
-
options[:start] ||= 0
|
16
|
-
options[:type] ||= (options[:start]).zero? ? :increment : :decrement
|
17
|
-
redis_objects[name.to_sym] = options.merge(type: :counter)
|
18
|
-
|
19
|
-
mod = Module.new do
|
20
|
-
define_method(name) do
|
21
|
-
Redis::HourlyCounter.new(
|
22
|
-
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if options[:global]
|
28
|
-
extend mod
|
29
|
-
|
30
|
-
# dispatch to class methods
|
31
|
-
define_method(name) do
|
32
|
-
self.class.public_send(name)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
include mod
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/minutely_counter'
|
4
|
-
class Redis
|
5
|
-
module Objects
|
6
|
-
module MinutelyCounters
|
7
|
-
class << self
|
8
|
-
def included(klass)
|
9
|
-
klass.extend ClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def minutely_counter(name, options = {}) # rubocop:disable Metrics/MethodLength
|
15
|
-
options[:start] ||= 0
|
16
|
-
options[:type] ||= (options[:start]).zero? ? :increment : :decrement
|
17
|
-
redis_objects[name.to_sym] = options.merge(type: :counter)
|
18
|
-
|
19
|
-
mod = Module.new do
|
20
|
-
define_method(name) do
|
21
|
-
Redis::MinutelyCounter.new(
|
22
|
-
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if options[:global]
|
28
|
-
extend mod
|
29
|
-
|
30
|
-
# dispatch to class methods
|
31
|
-
define_method(name) do
|
32
|
-
self.class.public_send(name)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
include mod
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/daily_counter'
|
4
|
-
class Redis
|
5
|
-
module Objects
|
6
|
-
module MonthlyCounters
|
7
|
-
class << self
|
8
|
-
def included(klass)
|
9
|
-
klass.extend ClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def monthly_counter(name, options = {}) # rubocop:disable Metrics/MethodLength
|
15
|
-
options[:start] ||= 0
|
16
|
-
options[:type] ||= (options[:start]).zero? ? :increment : :decrement
|
17
|
-
redis_objects[name.to_sym] = options.merge(type: :counter)
|
18
|
-
|
19
|
-
mod = Module.new do
|
20
|
-
define_method(name) do
|
21
|
-
Redis::MonthlyCounter.new(
|
22
|
-
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if options[:global]
|
28
|
-
extend mod
|
29
|
-
|
30
|
-
# dispatch to class methods
|
31
|
-
define_method(name) do
|
32
|
-
self.class.public_send(name)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
include mod
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'redis/weekly_counter'
|
4
|
-
class Redis
|
5
|
-
module Objects
|
6
|
-
module WeeklyCounters
|
7
|
-
class << self
|
8
|
-
def included(klass)
|
9
|
-
klass.extend ClassMethods
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
def weekly_counter(name, options = {}) # rubocop:disable Metrics/MethodLength
|
15
|
-
options[:start] ||= 0
|
16
|
-
options[:type] ||= (options[:start]).zero? ? :increment : :decrement
|
17
|
-
redis_objects[name.to_sym] = options.merge(type: :counter)
|
18
|
-
|
19
|
-
mod = Module.new do
|
20
|
-
define_method(name) do
|
21
|
-
Redis::WeeklyCounter.new(
|
22
|
-
redis_field_key(name), redis_field_redis(name), redis_options(name)
|
23
|
-
)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
if options[:global]
|
28
|
-
extend mod
|
29
|
-
|
30
|
-
# dispatch to class methods
|
31
|
-
define_method(name) do
|
32
|
-
self.class.public_send(name)
|
33
|
-
end
|
34
|
-
else
|
35
|
-
include mod
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/lib/redis/weekly_counter.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "#{File.dirname(__FILE__)}/base_counter_object"
|
4
|
-
|
5
|
-
class Redis
|
6
|
-
class WeeklyCounter < BaseCounterObject
|
7
|
-
private
|
8
|
-
|
9
|
-
def redis_daily_field_key(date_or_time)
|
10
|
-
date_key = date_or_time.strftime('%YW%W')
|
11
|
-
[original_key, date_key].flatten.join(':')
|
12
|
-
end
|
13
|
-
|
14
|
-
def next_key(date, length)
|
15
|
-
date + 7 * (length - 1)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|