cache_toolbox 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Guardfile +2 -2
- data/lib/cache_toolbox.rb +1 -0
- data/lib/cache_toolbox/multistore.rb +46 -0
- data/lib/cache_toolbox/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6ffe43641c0416c58726b7f3dac4ee957fae2d7
|
4
|
+
data.tar.gz: 865d41d94501c35c1b28d12b89592bb3c7e7777b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1458b23b1ca624ed132b7c569fab2e589cefb049f3e2ad343af1a68b28c2a74d67c1fd8fcaad13dc205a28f4b84a552a471b5680a1783b4314b72824b336baf3
|
7
|
+
data.tar.gz: ee2d192e3357817566057b977910aa28866ba7862accba2f92da8ce16bc44f19362eed09316fef3b42f27fe8ea838d249f6b3e0a1329ac0733daf5c9b9fdb6c1
|
data/Guardfile
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
guard :rspec, cmd: 'bundle exec rspec' do
|
4
4
|
watch(%r{^spec/.+_spec\.rb$})
|
5
|
-
watch(%r{^lib/(.+)\.rb$})
|
6
|
-
watch('spec/spec_helper.rb')
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
6
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
7
7
|
end
|
8
8
|
|
9
9
|
guard :rubocop do
|
data/lib/cache_toolbox.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/cache'
|
4
|
+
|
5
|
+
# nodoc #
|
6
|
+
module CacheToolbox
|
7
|
+
# nodoc #
|
8
|
+
class Multistore < ::ActiveSupport::Cache::Store
|
9
|
+
def initialize(options = {})
|
10
|
+
super(options)
|
11
|
+
|
12
|
+
raise ArgumentError, 'Specify default store argument default: :{store name}' unless
|
13
|
+
options.key?(:default) && options[:default].is_a?(Symbol)
|
14
|
+
|
15
|
+
raise ArgumentError, 'Specify store list argument stores: {...}' unless
|
16
|
+
options.key?(:stores)
|
17
|
+
|
18
|
+
@default = options[:default]
|
19
|
+
|
20
|
+
@stores = options[:stores].map do |name, store|
|
21
|
+
[name, ::ActiveSupport::Cache.lookup_store(store)]
|
22
|
+
end.to_h
|
23
|
+
|
24
|
+
@stores[:default] = @stores[options[:default]]
|
25
|
+
|
26
|
+
# TODO: check if @stores[@default] exists
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def read_entry(key, options = nil)
|
32
|
+
store = @stores[merged_options(options)[:store] || :default]
|
33
|
+
store.send(:read_entry, key, options)
|
34
|
+
end
|
35
|
+
|
36
|
+
def write_entry(key, entry, options = nil)
|
37
|
+
store = @stores[merged_options(options)[:store] || :default]
|
38
|
+
store.send(:write_entry, key, entry, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_entry(key, options = nil)
|
42
|
+
store = @stores[merged_options(options)[:store] || :default]
|
43
|
+
store.send(:delete_entry, key, options)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tadas Sasnauskas
|
@@ -176,6 +176,7 @@ files:
|
|
176
176
|
- cache_toolbox.gemspec
|
177
177
|
- lib/cache_toolbox.rb
|
178
178
|
- lib/cache_toolbox/fixed_prefix.rb
|
179
|
+
- lib/cache_toolbox/multistore.rb
|
179
180
|
- lib/cache_toolbox/version.rb
|
180
181
|
homepage: https://github.com/tadas-s/cache_toolbox
|
181
182
|
licenses:
|