redis_key_manager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/circle.yml +17 -0
- data/lib/redis_key_manager.rb +3 -0
- data/lib/redis_key_manager/exceptions.rb +3 -0
- data/lib/redis_key_manager/manager.rb +29 -0
- data/lib/redis_key_manager/version.rb +3 -0
- data/redis_key_manager.gemspec +29 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 115535b16c16ab46fca148c745c83178aa527c5d
|
4
|
+
data.tar.gz: 470f7967052c7d34226d287ac6d009c22ca9b27e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5fb8bd8ff69de30bb78b3841d585e2499441d14b749af5dbef3592324e0e4e8b3614e70321b63ca48c4cef669ec258b61fd7a12d26c04dca6e040e76ba9ff54
|
7
|
+
data.tar.gz: 66569756bb9540d1fd7e59b122c4ef6f311b86e0fcf7a489aa2f9ec17f3a015f68f7be82300ebdcceb2e3f81dac50347490aba355c44dee290752dd323f5f8c5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Oneflare Pty Ltd
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# RedisKeyManager
|
2
|
+
|
3
|
+
[![Gem Version][GV img]][Gem Version]
|
4
|
+
[![Coverage Status][CS img]][Coverage Status]
|
5
|
+
[![Build Status][BS img]][Build Status]
|
6
|
+
|
7
|
+
RedisKeyManager provides a simple Ruby DSL for declaring the Redis key patterns used by your
|
8
|
+
application. Instead of repeating the same string literals and manual interpolations throughout your
|
9
|
+
application—with the corresponding risk of error and silent failure—RedisKeyManager
|
10
|
+
generates methods that return those keys, accepting named parameters corresponding to the
|
11
|
+
substitutions specified in each pattern.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# Gemfile
|
17
|
+
gem "redis_key_manager"
|
18
|
+
```
|
19
|
+
|
20
|
+
```
|
21
|
+
$ bundle
|
22
|
+
```
|
23
|
+
|
24
|
+
## Example Usage
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require "redis_key_manager"
|
28
|
+
|
29
|
+
# Declare your key patterns like this:
|
30
|
+
|
31
|
+
class MyRedisKeys
|
32
|
+
include RedisKeyManager::Manager
|
33
|
+
|
34
|
+
key :hits, "hits"
|
35
|
+
key :user, "user:[user_id]"
|
36
|
+
key :foo, "foo:[name]:bar:[boom]:[bam]"
|
37
|
+
end
|
38
|
+
|
39
|
+
# Use your keys like this:
|
40
|
+
|
41
|
+
key = MyRedisKeys.hits # => "hits"
|
42
|
+
Redis.current.incr(key)
|
43
|
+
|
44
|
+
key = MyRedisKeys.foo(name: "BOB", boom: 5, bam: 9) # => "foo:BOB:bar:5:9"
|
45
|
+
Redis.current.zadd(key, 1.3, 500)
|
46
|
+
```
|
47
|
+
|
48
|
+
The methods generated by `key` declarations helpfully raise exceptions if you don't pass the named
|
49
|
+
arguments they expect, or if the values you pass are nil.
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
MyRedisKeys.foo(name: "BOB", boom: 5, blop: 6)
|
53
|
+
# ArgumentError: Invalid arguments for MyRedisKeys.foo
|
54
|
+
|
55
|
+
MyRedisKeys.foo(name: "BOB", boom: 5)
|
56
|
+
# ArgumentError: Invalid arguments for MyRedisKeys.foo
|
57
|
+
|
58
|
+
MyRedisKeys.foo(name: "BOB", boom: 5, bam: nil)
|
59
|
+
# RedisKeyManager::InvalidKeyComponentError: Invalid Redis key component passed to MyRedisKeys.foo
|
60
|
+
```
|
61
|
+
|
62
|
+
## Development
|
63
|
+
|
64
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
65
|
+
|
66
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
67
|
+
|
68
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
69
|
+
|
70
|
+
Please ensure that you write tests for any commits, and that tests pass locally before you submit a PR.
|
71
|
+
To run tests, run `bundle exec rake spec`.
|
72
|
+
|
73
|
+
## Contributing
|
74
|
+
|
75
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Oneflare/redis_key_manager.
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
80
|
+
|
81
|
+
[Gem Version]: https://rubygems.org/gems/redis_key_manager
|
82
|
+
[Coverage Status]: https://coveralls.io/r/Oneflare/redis_key_manager
|
83
|
+
[Build Status]: https://circleci.com/gh/Oneflare/redis_key_manager
|
84
|
+
|
85
|
+
[GV img]: https://img.shields.io/gem/v/redis_key_manager.svg
|
86
|
+
[CS img]: https://img.shields.io/coveralls/matt-harvey/tabulo.svg
|
87
|
+
[BS img]: https://img.shields.io/circleci/project/github/Oneflare/redis_key_manager.svg
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "redis_key_manager"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
machine:
|
2
|
+
timezone: Australia/Sydney
|
3
|
+
ruby:
|
4
|
+
version: 2.3.1
|
5
|
+
|
6
|
+
database:
|
7
|
+
override:
|
8
|
+
- echo "Skipping DB section as DB is not needed"
|
9
|
+
|
10
|
+
dependencies:
|
11
|
+
override:
|
12
|
+
- bundle check --path=/home/ubuntu/.bundle || bundle install --path=/home/ubuntu/.bundle --jobs=4 --retry=3
|
13
|
+
|
14
|
+
test:
|
15
|
+
override:
|
16
|
+
- bundle exec rspec -r rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml
|
17
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module RedisKeyManager::Manager
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
|
5
|
+
# Set up `.key` class method on the including class/module, enabling us to do one-liner declarations of
|
6
|
+
# named key patterns at the top of that class/module.
|
7
|
+
def base.key(key, pattern)
|
8
|
+
class_name = self.name
|
9
|
+
placeholders = pattern.scan(/(?<=\[)[^\]]+(?=\])/).uniq.map(&:to_sym)
|
10
|
+
|
11
|
+
# Set up a singleton method on the including class/module, with which the key can be retrieved.
|
12
|
+
define_singleton_method(key) do |options = {}|
|
13
|
+
passed_option_keys = options.keys
|
14
|
+
required_option_keys = placeholders
|
15
|
+
if passed_option_keys.sort != required_option_keys.sort
|
16
|
+
raise ArgumentError, "Invalid arguments for #{class_name}.#{key}"
|
17
|
+
end
|
18
|
+
|
19
|
+
placeholders.inject(pattern) do |revised_pattern, placeholder|
|
20
|
+
value = options[placeholder]
|
21
|
+
if value.nil?
|
22
|
+
raise RedisKeyManager::InvalidKeyComponentError, "Invalid Redis key component passed to #{class_name}.#{key}"
|
23
|
+
end
|
24
|
+
revised_pattern.gsub("[#{placeholder}]", value.to_s)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "redis_key_manager/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "redis_key_manager"
|
8
|
+
spec.version = RedisKeyManager::VERSION
|
9
|
+
spec.authors = ["Matthew Harvey"]
|
10
|
+
spec.email = ["matthewh@oneflare.com"]
|
11
|
+
|
12
|
+
spec.summary = "Redis key manager"
|
13
|
+
spec.description = "Programmatically declare and enforce the Redis key patterns used by your project"
|
14
|
+
spec.homepage = "https://github.com/Oneflare/redis_key_manager"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
spec.add_development_dependency "rspec_junit_formatter", "~> 0.2"
|
28
|
+
spec.add_development_dependency "simplecov", "~> 0.10.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis_key_manager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew Harvey
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.0
|
83
|
+
description: Programmatically declare and enforce the Redis key patterns used by your
|
84
|
+
project
|
85
|
+
email:
|
86
|
+
- matthewh@oneflare.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE.txt
|
95
|
+
- README.md
|
96
|
+
- Rakefile
|
97
|
+
- bin/console
|
98
|
+
- bin/setup
|
99
|
+
- circle.yml
|
100
|
+
- lib/redis_key_manager.rb
|
101
|
+
- lib/redis_key_manager/exceptions.rb
|
102
|
+
- lib/redis_key_manager/manager.rb
|
103
|
+
- lib/redis_key_manager/version.rb
|
104
|
+
- redis_key_manager.gemspec
|
105
|
+
homepage: https://github.com/Oneflare/redis_key_manager
|
106
|
+
licenses:
|
107
|
+
- MIT
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.2.0
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Redis key manager
|
129
|
+
test_files: []
|