cache_box 0.0.1.pre.preview1 → 0.0.1.pre.preview2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cache_box.gemspec +1 -1
- data/lib/cache_box.rb +10 -9
- data/lib/cache_box_chain.rb +7 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffc75a2d7008957a8c53dabf66772390d5eca8e964f6ab92f35fe57c063d5e52
|
4
|
+
data.tar.gz: 28c08be79e3a089f14897a42805a3a3b0b12f44a49c8fda8bc81884763aacc72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 948602c9c4a3aac655c6a2c13a8284d92f9da2246a7b901133c050adb2119ceadb4936fe750cb27ab5d5afe383326e2e02cf623fb5c3d5145acb6a9dce289aa2
|
7
|
+
data.tar.gz: c8f3529d877814c4007d31699dabbd4fc375714b52184f36ec6660f3c126463f90afbe522c5e7eee42f62c0495ea9483753f02de66f533297dd855ec0b20f88e
|
data/cache_box.gemspec
CHANGED
data/lib/cache_box.rb
CHANGED
@@ -4,7 +4,7 @@ require 'fileutils'
|
|
4
4
|
require_relative 'cache_box_chain'
|
5
5
|
|
6
6
|
class CacheBox
|
7
|
-
def initialize(namespace = :
|
7
|
+
def initialize(namespace = :namespace)
|
8
8
|
validate!(namespace, 'namespace')
|
9
9
|
|
10
10
|
@namespace = namespace
|
@@ -13,13 +13,13 @@ class CacheBox
|
|
13
13
|
@directory = File.join(@root, @namespace.to_s)
|
14
14
|
end
|
15
15
|
|
16
|
-
def reset!(namespace = :
|
16
|
+
def reset!(namespace = :namespace)
|
17
17
|
initialize(namespace)
|
18
18
|
|
19
19
|
self
|
20
20
|
end
|
21
21
|
|
22
|
-
def with(name = :
|
22
|
+
def with(name = :name, *args)
|
23
23
|
validate!(name, 'name')
|
24
24
|
|
25
25
|
file = File.join(@directory, name.to_s)
|
@@ -29,7 +29,7 @@ class CacheBox
|
|
29
29
|
store(yield(*args), name, file)
|
30
30
|
end
|
31
31
|
|
32
|
-
def with_many(name = :
|
32
|
+
def with_many(name = :name, *args)
|
33
33
|
validate!(name, 'name')
|
34
34
|
|
35
35
|
file = File.join(@directory, name.to_s)
|
@@ -45,7 +45,7 @@ class CacheBox
|
|
45
45
|
storage
|
46
46
|
end
|
47
47
|
|
48
|
-
def has?(name = :
|
48
|
+
def has?(name = :name)
|
49
49
|
validate!(name, 'name')
|
50
50
|
|
51
51
|
file = File.join(@directory, name.to_s)
|
@@ -61,7 +61,7 @@ class CacheBox
|
|
61
61
|
self
|
62
62
|
end
|
63
63
|
|
64
|
-
def expire(name = :
|
64
|
+
def expire(name = :name)
|
65
65
|
validate!(name, 'name')
|
66
66
|
|
67
67
|
@state.delete(name)
|
@@ -74,12 +74,12 @@ class CacheBox
|
|
74
74
|
private
|
75
75
|
|
76
76
|
def validate!(arg, name)
|
77
|
-
return if arg.is_a?(Symbol)
|
77
|
+
return if arg.is_a?(Symbol) || arg.is_a?(String)
|
78
78
|
|
79
79
|
klass = arg.class
|
80
80
|
value = arg.inspect
|
81
81
|
|
82
|
-
raise(ArgumentError, "#{name} must be a Symbol, got #{klass}: #{value}")
|
82
|
+
raise(ArgumentError, "#{name} must be a Symbol or String, got #{klass}: #{value}")
|
83
83
|
end
|
84
84
|
|
85
85
|
def load!(name, file)
|
@@ -100,7 +100,8 @@ class CacheBox
|
|
100
100
|
|
101
101
|
content = Marshal.dump(value)
|
102
102
|
|
103
|
-
|
103
|
+
directory = File.dirname(file)
|
104
|
+
FileUtils.mkdir_p(directory) unless Dir.exist?(directory)
|
104
105
|
File.write(file, content)
|
105
106
|
|
106
107
|
value
|
data/lib/cache_box_chain.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
class CacheBox
|
4
4
|
class Chain
|
5
|
-
def initialize(namespace = :
|
5
|
+
def initialize(namespace = :namespace)
|
6
6
|
@cache = ::CacheBox.new(namespace)
|
7
7
|
@chain = []
|
8
8
|
end
|
9
9
|
|
10
|
-
def reset!(namespace = :
|
10
|
+
def reset!(namespace = :namespace)
|
11
11
|
@cache.reset!(namespace)
|
12
12
|
@chain = []
|
13
13
|
|
@@ -61,11 +61,14 @@ class CacheBox
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def validate_chain!(name, &block)
|
64
|
-
unless name.is_a?(Symbol)
|
64
|
+
unless name.is_a?(Symbol) || name.is_a?(String)
|
65
65
|
klass = name.class
|
66
66
|
value = name.inspect
|
67
67
|
|
68
|
-
raise(
|
68
|
+
raise(
|
69
|
+
ArgumentError,
|
70
|
+
"name must be a Symbol or a String, got #{klass}: #{value}"
|
71
|
+
)
|
69
72
|
end
|
70
73
|
|
71
74
|
return unless block.nil?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cache_box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre.
|
4
|
+
version: 0.0.1.pre.preview2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Codruț Constantin Gușoi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|