kvmultiplex 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +164 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +10 -0
- data/bin/setup +8 -0
- data/kvmultiplex.gemspec +29 -0
- data/lib/kvmultiplex/multiplexer.rb +121 -0
- data/lib/kvmultiplex/provider.rb +11 -0
- data/lib/kvmultiplex/providers/memory.rb +36 -0
- data/lib/kvmultiplex/providers/readonly.rb +19 -0
- data/lib/kvmultiplex/version.rb +3 -0
- data/lib/kvmultiplex.rb +6 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 993854d6cc7f82bf185322fde0aeba99cb66b66d
|
4
|
+
data.tar.gz: 3bed16cd0684f35011616a737aa655ebc6f6c893
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 327e0127d4fd2583cc4560f4d2358cc706d92e35944e231347b8cd3bdb5ef95f55516bdb7c54410fb72cbec1752f93c7f2bcc29da1eb1b59b19dd7ec40c65753
|
7
|
+
data.tar.gz: 8d3cd05ba746b3278806bb51d8d7ec77e790e3225d83916a0374cd1620312c95db5462c81633dbf27e061b346e67916a62965fe611d5e24a1de8d52d2286f866
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
Layout/EmptyLineAfterMagicComment:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
# Relaxed.Ruby.Style
|
5
|
+
## Version 2.1
|
6
|
+
|
7
|
+
Style/Alias:
|
8
|
+
Enabled: false
|
9
|
+
StyleGuide: http://relaxed.ruby.style/#stylealias
|
10
|
+
|
11
|
+
Style/AsciiComments:
|
12
|
+
Enabled: false
|
13
|
+
StyleGuide: http://relaxed.ruby.style/#styleasciicomments
|
14
|
+
|
15
|
+
Style/BeginBlock:
|
16
|
+
Enabled: false
|
17
|
+
StyleGuide: http://relaxed.ruby.style/#stylebeginblock
|
18
|
+
|
19
|
+
Style/BlockDelimiters:
|
20
|
+
Enabled: false
|
21
|
+
StyleGuide: http://relaxed.ruby.style/#styleblockdelimiters
|
22
|
+
|
23
|
+
Style/CommentAnnotation:
|
24
|
+
Enabled: false
|
25
|
+
StyleGuide: http://relaxed.ruby.style/#stylecommentannotation
|
26
|
+
|
27
|
+
Style/Documentation:
|
28
|
+
Enabled: false
|
29
|
+
StyleGuide: http://relaxed.ruby.style/#styledocumentation
|
30
|
+
|
31
|
+
Layout/DotPosition:
|
32
|
+
Enabled: false
|
33
|
+
StyleGuide: http://relaxed.ruby.style/#layoutdotposition
|
34
|
+
|
35
|
+
Style/DoubleNegation:
|
36
|
+
Enabled: false
|
37
|
+
StyleGuide: http://relaxed.ruby.style/#styledoublenegation
|
38
|
+
|
39
|
+
Style/EndBlock:
|
40
|
+
Enabled: false
|
41
|
+
StyleGuide: http://relaxed.ruby.style/#styleendblock
|
42
|
+
|
43
|
+
Style/FormatString:
|
44
|
+
Enabled: false
|
45
|
+
StyleGuide: http://relaxed.ruby.style/#styleformatstring
|
46
|
+
|
47
|
+
Style/IfUnlessModifier:
|
48
|
+
Enabled: false
|
49
|
+
StyleGuide: http://relaxed.ruby.style/#styleifunlessmodifier
|
50
|
+
|
51
|
+
Style/Lambda:
|
52
|
+
Enabled: false
|
53
|
+
StyleGuide: http://relaxed.ruby.style/#stylelambda
|
54
|
+
|
55
|
+
Style/ModuleFunction:
|
56
|
+
Enabled: false
|
57
|
+
StyleGuide: http://relaxed.ruby.style/#stylemodulefunction
|
58
|
+
|
59
|
+
Style/MultilineBlockChain:
|
60
|
+
Enabled: false
|
61
|
+
StyleGuide: http://relaxed.ruby.style/#stylemultilineblockchain
|
62
|
+
|
63
|
+
Style/NegatedIf:
|
64
|
+
Enabled: false
|
65
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedif
|
66
|
+
|
67
|
+
Style/NegatedWhile:
|
68
|
+
Enabled: false
|
69
|
+
StyleGuide: http://relaxed.ruby.style/#stylenegatedwhile
|
70
|
+
|
71
|
+
Style/ParallelAssignment:
|
72
|
+
Enabled: false
|
73
|
+
StyleGuide: http://relaxed.ruby.style/#styleparallelassignment
|
74
|
+
|
75
|
+
Style/PercentLiteralDelimiters:
|
76
|
+
Enabled: false
|
77
|
+
StyleGuide: http://relaxed.ruby.style/#stylepercentliteraldelimiters
|
78
|
+
|
79
|
+
Style/PerlBackrefs:
|
80
|
+
Enabled: false
|
81
|
+
StyleGuide: http://relaxed.ruby.style/#styleperlbackrefs
|
82
|
+
|
83
|
+
Style/Semicolon:
|
84
|
+
Enabled: false
|
85
|
+
StyleGuide: http://relaxed.ruby.style/#stylesemicolon
|
86
|
+
|
87
|
+
Style/SignalException:
|
88
|
+
Enabled: false
|
89
|
+
StyleGuide: http://relaxed.ruby.style/#stylesignalexception
|
90
|
+
|
91
|
+
Style/SingleLineBlockParams:
|
92
|
+
Enabled: false
|
93
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelineblockparams
|
94
|
+
|
95
|
+
Style/SingleLineMethods:
|
96
|
+
Enabled: false
|
97
|
+
StyleGuide: http://relaxed.ruby.style/#stylesinglelinemethods
|
98
|
+
|
99
|
+
Layout/SpaceBeforeBlockBraces:
|
100
|
+
Enabled: false
|
101
|
+
StyleGuide: http://relaxed.ruby.style/#layoutspacebeforeblockbraces
|
102
|
+
|
103
|
+
Layout/SpaceInsideParens:
|
104
|
+
Enabled: false
|
105
|
+
StyleGuide: http://relaxed.ruby.style/#layoutspaceinsideparens
|
106
|
+
|
107
|
+
Style/SpecialGlobalVars:
|
108
|
+
Enabled: false
|
109
|
+
StyleGuide: http://relaxed.ruby.style/#stylespecialglobalvars
|
110
|
+
|
111
|
+
Style/StringLiterals:
|
112
|
+
Enabled: false
|
113
|
+
StyleGuide: http://relaxed.ruby.style/#stylestringliterals
|
114
|
+
|
115
|
+
Style/TrailingCommaInArguments:
|
116
|
+
Enabled: false
|
117
|
+
StyleGuide: http://relaxed.ruby.style/#styletrailingcommainarguments
|
118
|
+
|
119
|
+
Style/TrailingCommaInLiteral:
|
120
|
+
Enabled: false
|
121
|
+
StyleGuide: http://relaxed.ruby.style/#styletrailingcommainliteral
|
122
|
+
|
123
|
+
Style/WhileUntilModifier:
|
124
|
+
Enabled: false
|
125
|
+
StyleGuide: http://relaxed.ruby.style/#stylewhileuntilmodifier
|
126
|
+
|
127
|
+
Style/WordArray:
|
128
|
+
Enabled: false
|
129
|
+
StyleGuide: http://relaxed.ruby.style/#stylewordarray
|
130
|
+
|
131
|
+
Lint/AmbiguousRegexpLiteral:
|
132
|
+
Enabled: false
|
133
|
+
StyleGuide: http://relaxed.ruby.style/#lintambiguousregexpliteral
|
134
|
+
|
135
|
+
Lint/AssignmentInCondition:
|
136
|
+
Enabled: false
|
137
|
+
StyleGuide: http://relaxed.ruby.style/#lintassignmentincondition
|
138
|
+
|
139
|
+
Metrics/AbcSize:
|
140
|
+
Enabled: false
|
141
|
+
|
142
|
+
Metrics/BlockNesting:
|
143
|
+
Enabled: false
|
144
|
+
|
145
|
+
Metrics/ClassLength:
|
146
|
+
Enabled: false
|
147
|
+
|
148
|
+
Metrics/ModuleLength:
|
149
|
+
Enabled: false
|
150
|
+
|
151
|
+
Metrics/CyclomaticComplexity:
|
152
|
+
Enabled: false
|
153
|
+
|
154
|
+
Metrics/LineLength:
|
155
|
+
Enabled: false
|
156
|
+
|
157
|
+
Metrics/MethodLength:
|
158
|
+
Enabled: false
|
159
|
+
|
160
|
+
Metrics/ParameterLists:
|
161
|
+
Enabled: false
|
162
|
+
|
163
|
+
Metrics/PerceivedComplexity:
|
164
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ed@edropple.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ed Ropple
|
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,43 @@
|
|
1
|
+
# Kvmultiplex
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kvmultiplex`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'kvmultiplex'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install kvmultiplex
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kvmultiplex. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the Kvmultiplex project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kvmultiplex/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/kvmultiplex.gemspec
ADDED
@@ -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 "kvmultiplex/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kvmultiplex"
|
8
|
+
spec.version = KVMultiplex::VERSION
|
9
|
+
spec.authors = ["Ed Ropple"]
|
10
|
+
spec.email = ["ed@edropple.com"]
|
11
|
+
|
12
|
+
spec.summary = "A tool for multiplexing key-value lookups across many sources."
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
|
27
|
+
spec.add_runtime_dependency "diff-lcs", "~> 1.3"
|
28
|
+
spec.add_runtime_dependency "deep_merge", "~> 1.1"
|
29
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'kvmultiplex/provider'
|
2
|
+
|
3
|
+
require 'logger';
|
4
|
+
require 'diff-lcs'
|
5
|
+
|
6
|
+
module KVMultiplex
|
7
|
+
class Multiplexer
|
8
|
+
attr_reader :logger
|
9
|
+
|
10
|
+
def initialize(delimiter: ".", logger: Logger.new)
|
11
|
+
@logger = logger
|
12
|
+
@delimiter = delimiter.dup
|
13
|
+
|
14
|
+
@providers = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def register(prefix, provider, prepend: false)
|
18
|
+
raise "provider must be a KVMultiplex::Provider." unless provider.is_a?(KVMultiplex::Provider)
|
19
|
+
|
20
|
+
prefix =
|
21
|
+
if prefix.is_a?(String)
|
22
|
+
prefix.split(@delimiter).freeze
|
23
|
+
elsif prefix.is_a?(Array) && prefix.all? { |i| i.is_a?(String) }
|
24
|
+
prefix.map { |i| i.to_s.dup }.freeze
|
25
|
+
else
|
26
|
+
raise "prefix must be a String or array of Strings."
|
27
|
+
end
|
28
|
+
|
29
|
+
@providers[prefix] ||= []
|
30
|
+
|
31
|
+
if prepend
|
32
|
+
@providers[prefix].unshift provider
|
33
|
+
else
|
34
|
+
@providers[prefix].push provider
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def get!(key)
|
39
|
+
ret = get(key)
|
40
|
+
raise "Value not found for key: #{key}" if ret.nil?
|
41
|
+
ret
|
42
|
+
end
|
43
|
+
|
44
|
+
def get(key)
|
45
|
+
providers, subkey, full_key = find_providers_for_key(key)
|
46
|
+
|
47
|
+
if providers.nil? || providers.empty?
|
48
|
+
logger.warn "No providers for '#{full_key.inspect}'."
|
49
|
+
nil
|
50
|
+
else
|
51
|
+
ret = providers.find { |provider| provider.get(subkey, full_key) }
|
52
|
+
logger.warn "No values found for '#{full_key.inspect}'." if ret.nil?
|
53
|
+
|
54
|
+
ret
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def set(key, value)
|
59
|
+
providers, subkey, full_key = find_providers_for_key(key)
|
60
|
+
|
61
|
+
if providers.nil? || providers.empty?
|
62
|
+
logger.warn "No providers for '#{full_key.inspect}'."
|
63
|
+
nil
|
64
|
+
else
|
65
|
+
logger.warn "Multiple providers found for '#{full_key.inspect}'; this might cause surprising behavior!" \
|
66
|
+
unless providers.size == 1
|
67
|
+
|
68
|
+
ret = providers.find do |provider|
|
69
|
+
logger.debug "Attempting to set into #{provider}."
|
70
|
+
p_ret = provider.set(subkey, full_key, value)
|
71
|
+
|
72
|
+
logger.debug "Failed to set into #{provider}." if p_ret.nil?
|
73
|
+
!p_ret.nil?
|
74
|
+
end
|
75
|
+
|
76
|
+
raise "No provider able to set '#{full_key.inspect}'." unless ret
|
77
|
+
ret
|
78
|
+
end
|
79
|
+
|
80
|
+
value
|
81
|
+
end
|
82
|
+
|
83
|
+
def find_providers_for_key(key)
|
84
|
+
logger.debug "Key lookup for '#{key.inspect}'."
|
85
|
+
|
86
|
+
key =
|
87
|
+
if key.is_a?(String)
|
88
|
+
key.split(@delimiter).freeze
|
89
|
+
elsif key.is_a?(Array) && key.all? { |i| i.is_a?(String) }
|
90
|
+
key.map(&:to_s).freeze
|
91
|
+
else
|
92
|
+
raise "key must be a String or array of Strings."
|
93
|
+
end
|
94
|
+
|
95
|
+
key_length = key.size
|
96
|
+
|
97
|
+
longest = -1
|
98
|
+
longest_prefix = nil
|
99
|
+
matched_providers = nil
|
100
|
+
|
101
|
+
@providers.each_pair do |prefix, providers|
|
102
|
+
lcs_length = Diff::LCS.LCS(key, prefix).length
|
103
|
+
|
104
|
+
next unless [longest, lcs_length].max == prefix.length
|
105
|
+
|
106
|
+
longest = lcs_length
|
107
|
+
longest_prefix = prefix
|
108
|
+
matched_providers = providers
|
109
|
+
break if key_length == lcs_length # we've matched exactly
|
110
|
+
end
|
111
|
+
|
112
|
+
if matched_providers.nil?
|
113
|
+
[nil, nil, key]
|
114
|
+
else
|
115
|
+
subkey = key - longest_prefix
|
116
|
+
|
117
|
+
[matched_providers, subkey, key]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "kvmultiplex/provider"
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "deep_merge"
|
5
|
+
|
6
|
+
module KVMultiplex
|
7
|
+
module Providers
|
8
|
+
# The `Memory` provider just stores a list of potential values. Since other
|
9
|
+
# providers are sparse trees (there's no "list" operation), we're just going
|
10
|
+
# to store values as complete subkeys, stringified internally to avoid
|
11
|
+
# accidentally changing a subkey further down the line.
|
12
|
+
class Memory < KVMultiplex::Provider
|
13
|
+
def initialize
|
14
|
+
@contents = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def get(subkey, _full_key)
|
18
|
+
v = @contents[get_content_key(subkey)]
|
19
|
+
v.nil? ? v : JSON.parse(v)
|
20
|
+
end
|
21
|
+
|
22
|
+
def set(subkey, _full_key, value)
|
23
|
+
# do NOT use JSON.generate here; it's unsafe in environments that pull json 1.8.6
|
24
|
+
@contents[get_content_key(subkey)] = value.nil? ? nil : value.to_json
|
25
|
+
value
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def get_content_key(subkey)
|
31
|
+
# Was originally a SHA1 hash, but I think that might be overkill.
|
32
|
+
subkey.join('.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "kvmultiplex/provider"
|
2
|
+
|
3
|
+
require "deep_merge/rails_compat"
|
4
|
+
|
5
|
+
module KVMultiplex
|
6
|
+
module Providers
|
7
|
+
class Readonly < KVMultiplex::Provider
|
8
|
+
def initialize(provider)
|
9
|
+
raise "provider must be a KVMultiplex::Provider." unless provider.is_a?(KVMultiplex::Provider)
|
10
|
+
|
11
|
+
@provider = provider
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(subkey, full_key)
|
15
|
+
@provider.get(subkey, full_key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/kvmultiplex.rb
ADDED
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kvmultiplex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.7
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed Ropple
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-10-27 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
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: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: diff-lcs
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: deep_merge
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.1'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.1'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- ed@edropple.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- bin/console
|
114
|
+
- bin/setup
|
115
|
+
- kvmultiplex.gemspec
|
116
|
+
- lib/kvmultiplex.rb
|
117
|
+
- lib/kvmultiplex/multiplexer.rb
|
118
|
+
- lib/kvmultiplex/provider.rb
|
119
|
+
- lib/kvmultiplex/providers/memory.rb
|
120
|
+
- lib/kvmultiplex/providers/readonly.rb
|
121
|
+
- lib/kvmultiplex/version.rb
|
122
|
+
homepage:
|
123
|
+
licenses:
|
124
|
+
- MIT
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.6.11
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: A tool for multiplexing key-value lookups across many sources.
|
146
|
+
test_files: []
|