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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a12c59684897ea560af23741dad332a9089ecf1
4
- data.tar.gz: 4bd3b1081e156efd8e9d9df1162ff78daa764df4
3
+ metadata.gz: c6ffe43641c0416c58726b7f3dac4ee957fae2d7
4
+ data.tar.gz: 865d41d94501c35c1b28d12b89592bb3c7e7777b
5
5
  SHA512:
6
- metadata.gz: fa2ed18170489ed2aa34fb8221b0f543d42a7550fa79aa004d69edba6e9fc59775751421df5ca5ac95c70a6ea76ca40ca20f485ef3a2a31ded13631e28071cb5
7
- data.tar.gz: 28c51c074a2a26df3ce47e63e1c73c723f4a723124bc0d1e740a36430becaaa65695cac0ba3a3ca991cc6d4320d3005a437bcd6a17536b64d472ef11bd2dfb3d
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$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
6
- watch('spec/spec_helper.rb') { 'spec' }
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
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative 'cache_toolbox/version'
4
4
  require_relative 'cache_toolbox/fixed_prefix'
5
+ require_relative 'cache_toolbox/multistore'
5
6
 
6
7
  # nodoc #
7
8
  module CacheToolbox
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CacheToolbox
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  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.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: