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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 19b591535ab5ba124dca095013f08a3be9b348e0138a1738ec6c3088f388e8b9
4
- data.tar.gz: 33183202f61274a5f3cfbae070bb83a8f2749b99596daeb98a43f173da8e5ea7
3
+ metadata.gz: ffc75a2d7008957a8c53dabf66772390d5eca8e964f6ab92f35fe57c063d5e52
4
+ data.tar.gz: 28c08be79e3a089f14897a42805a3a3b0b12f44a49c8fda8bc81884763aacc72
5
5
  SHA512:
6
- metadata.gz: e14a3c9b73792b6debc38676ce17f28ecfc81981e96476c7d6038ef4a1b9cd9af48513fc4569b9155edb5aa1c685e0ed2ad7844be2ff4e98ae905dce131fdff0
7
- data.tar.gz: fd250b2db538d59d215ab656def286afca52d09894d1ea667484a1927441bd1d50638c5a1f0c187a89fb92cb40f7863c5b018fba8ae47867eec15df65edb8233
6
+ metadata.gz: 948602c9c4a3aac655c6a2c13a8284d92f9da2246a7b901133c050adb2119ceadb4936fe750cb27ab5d5afe383326e2e02cf623fb5c3d5145acb6a9dce289aa2
7
+ data.tar.gz: c8f3529d877814c4007d31699dabbd4fc375714b52184f36ec6660f3c126463f90afbe522c5e7eee42f62c0495ea9483753f02de66f533297dd855ec0b20f88e
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'cache_box'
5
- spec.version = '0.0.1-preview1'
5
+ spec.version = '0.0.1-preview2'
6
6
  spec.authors = ['Codruț Constantin Gușoi']
7
7
  spec.email = ['codrut.gusoi+git-commit@gmail.com']
8
8
 
@@ -4,7 +4,7 @@ require 'fileutils'
4
4
  require_relative 'cache_box_chain'
5
5
 
6
6
  class CacheBox
7
- def initialize(namespace = :default_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 = :default_namespace)
16
+ def reset!(namespace = :namespace)
17
17
  initialize(namespace)
18
18
 
19
19
  self
20
20
  end
21
21
 
22
- def with(name = :default_name, *args)
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 = :default_name, *args)
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 = :default_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 = :default_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
- FileUtils.mkdir_p(@directory) unless Dir.exist?(@directory)
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
@@ -2,12 +2,12 @@
2
2
 
3
3
  class CacheBox
4
4
  class Chain
5
- def initialize(namespace = :default_namespace)
5
+ def initialize(namespace = :namespace)
6
6
  @cache = ::CacheBox.new(namespace)
7
7
  @chain = []
8
8
  end
9
9
 
10
- def reset!(namespace = :default_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(ArgumentError, "name must be a Symbol, got #{klass}: #{value}")
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.preview1
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-17 00:00:00.000000000 Z
11
+ date: 2020-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest