redis-objects-periodical 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +207 -0
  3. data/.gem_comet.yml +24 -0
  4. data/.github/dependabot.yml +19 -0
  5. data/.gitignore +11 -0
  6. data/.rspec +3 -0
  7. data/.rubocop.yml +40 -0
  8. data/.rubocop_todo.yml +16 -0
  9. data/CHANGELOG.md +112 -0
  10. data/CODE_OF_CONDUCT.md +84 -0
  11. data/Dockerfile +7 -0
  12. data/Gemfile +18 -0
  13. data/Gemfile.lock +98 -0
  14. data/LICENSE.txt +21 -0
  15. data/README.md +222 -0
  16. data/Rakefile +15 -0
  17. data/bin/console +14 -0
  18. data/bin/setup +8 -0
  19. data/docker-compose.yml +17 -0
  20. data/lib/redis/base_counter_object.rb +27 -0
  21. data/lib/redis/base_hash_key_object.rb +40 -0
  22. data/lib/redis/base_set_object.rb +28 -0
  23. data/lib/redis/objects/periodical/version.rb +9 -0
  24. data/lib/redis/objects/periodical_counters.rb +40 -0
  25. data/lib/redis/objects/periodical_hashes.rb +50 -0
  26. data/lib/redis/objects/periodical_sets.rb +50 -0
  27. data/lib/redis/periodical_counter.rb +15 -0
  28. data/lib/redis/periodical_hash_key.rb +15 -0
  29. data/lib/redis/periodical_set.rb +15 -0
  30. data/lib/redis/recurring_at_intervals/annual.rb +18 -0
  31. data/lib/redis/recurring_at_intervals/daily.rb +18 -0
  32. data/lib/redis/recurring_at_intervals/hourly.rb +18 -0
  33. data/lib/redis/recurring_at_intervals/minutely.rb +18 -0
  34. data/lib/redis/recurring_at_intervals/monthly.rb +18 -0
  35. data/lib/redis/recurring_at_intervals/weekly.rb +18 -0
  36. data/lib/redis/recurring_at_intervals.rb +79 -0
  37. data/lib/redis-objects-periodical.rb +36 -0
  38. data/redis-objects-daily-counter.gemspec +36 -0
  39. data/redis-objects-periodical.gemspec +36 -0
  40. metadata +99 -0
@@ -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
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'redis-objects-daily-counter'
5
+ spec.version = '0.4.0'
6
+ spec.authors = ['ryz310']
7
+ spec.email = ['ryz310@gmail.com']
8
+
9
+ spec.summary = 'Daily counter within Redis::Objects'
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.'
14
+ spec.homepage = 'https://github.com/ryz310/redis-objects-daily-counter'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/ryz310/redis-objects-daily-counter'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/ryz310/redis-objects-daily-counter/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
@@ -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 ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-objects-periodical
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - ryz310
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis-objects
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Extends Redis::Objects to switch automatically the save destination within
28
+ Redis on changing dates.
29
+ email:
30
+ - ryz310@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".circleci/config.yml"
36
+ - ".gem_comet.yml"
37
+ - ".github/dependabot.yml"
38
+ - ".gitignore"
39
+ - ".rspec"
40
+ - ".rubocop.yml"
41
+ - ".rubocop_todo.yml"
42
+ - CHANGELOG.md
43
+ - CODE_OF_CONDUCT.md
44
+ - Dockerfile
45
+ - Gemfile
46
+ - Gemfile.lock
47
+ - LICENSE.txt
48
+ - README.md
49
+ - Rakefile
50
+ - bin/console
51
+ - bin/setup
52
+ - docker-compose.yml
53
+ - lib/redis-objects-periodical.rb
54
+ - lib/redis/base_counter_object.rb
55
+ - lib/redis/base_hash_key_object.rb
56
+ - lib/redis/base_set_object.rb
57
+ - lib/redis/objects/periodical/version.rb
58
+ - lib/redis/objects/periodical_counters.rb
59
+ - lib/redis/objects/periodical_hashes.rb
60
+ - lib/redis/objects/periodical_sets.rb
61
+ - lib/redis/periodical_counter.rb
62
+ - lib/redis/periodical_hash_key.rb
63
+ - lib/redis/periodical_set.rb
64
+ - lib/redis/recurring_at_intervals.rb
65
+ - lib/redis/recurring_at_intervals/annual.rb
66
+ - lib/redis/recurring_at_intervals/daily.rb
67
+ - lib/redis/recurring_at_intervals/hourly.rb
68
+ - lib/redis/recurring_at_intervals/minutely.rb
69
+ - lib/redis/recurring_at_intervals/monthly.rb
70
+ - lib/redis/recurring_at_intervals/weekly.rb
71
+ - redis-objects-daily-counter.gemspec
72
+ - redis-objects-periodical.gemspec
73
+ homepage: https://github.com/ryz310/redis-objects-periodical
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/ryz310/redis-objects-periodical
78
+ source_code_uri: https://github.com/ryz310/redis-objects-periodical
79
+ changelog_uri: https://github.com/ryz310/redis-objects-periodical/blob/master/CHANGELOG.md
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 2.7.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.3.7
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Extends Redis::Objects as periodical.
99
+ test_files: []