cache_box 0.0.1.pre.preview4 → 0.0.1.pre.preview9

Sign up to get free protection for your applications and to get access to all the features.
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.preview4
4
+ version: 0.0.1.pre.preview9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Codruț Constantin Gușoi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-19 00:00:00.000000000 Z
11
+ date: 2020-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -66,9 +66,23 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.88'
69
- description:
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.18'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.18'
83
+ description:
70
84
  email:
71
- - codrut.gusoi+git-commit@gmail.com
85
+ - codrut.gusoi+rubygems.org@gmail.com
72
86
  executables: []
73
87
  extensions: []
74
88
  extra_rdoc_files: []
@@ -76,12 +90,24 @@ files:
76
90
  - LICENSE
77
91
  - cache_box.gemspec
78
92
  - lib/cache_box.rb
79
- - lib/cache_box_chain.rb
93
+ - lib/cache_box/box.rb
94
+ - lib/cache_box/chain.rb
95
+ - lib/cache_box/graph.rb
96
+ - lib/cache_box/helper/validate.rb
97
+ - lib/cache_box/scheduler/base.rb
98
+ - lib/cache_box/scheduler/concurrent.rb
99
+ - lib/cache_box/scheduler/serial.rb
100
+ - lib/cache_box/stash.rb
101
+ - lib/cache_box/storage/file.rb
102
+ - lib/cache_box/storage/memory.rb
103
+ - lib/cache_box/unit.rb
80
104
  homepage: https://gitlab.com/sdwolfz/cache_box_rb
81
105
  licenses:
82
- - BSD 3-clause
83
- metadata: {}
84
- post_install_message:
106
+ - BSD-3-Clause
107
+ metadata:
108
+ homepage_uri: https://gitlab.com/sdwolfz/cache_box_rb
109
+ source_code_uri: https://gitlab.com/sdwolfz/cache_box_rb
110
+ post_install_message:
85
111
  rdoc_options: []
86
112
  require_paths:
87
113
  - lib
@@ -96,8 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
122
  - !ruby/object:Gem::Version
97
123
  version: 1.3.1
98
124
  requirements: []
99
- rubygems_version: 3.1.3
100
- signing_key:
125
+ rubygems_version: 3.1.2
126
+ signing_key:
101
127
  specification_version: 4
102
- summary: A simple, fast, and easy to use file backed cache.
128
+ summary: A simple, fast, and easy to use local cache.
103
129
  test_files: []
@@ -1,177 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class CacheBox
4
- class Chain
5
- # Input:
6
- #
7
- # namespace = String | Symbol # Default: :namespace
8
- #
9
- # Output: N/A
10
- def initialize(namespace = :namespace)
11
- @cache = ::CacheBox.new(namespace)
12
- @chain = []
13
- end
14
-
15
- # Input:
16
- #
17
- # namespace = String | Symbol # Default: :namespace
18
- #
19
- # Output: self
20
- def reset!(namespace = :namespace)
21
- @cache.reset!(namespace)
22
- @chain = []
23
-
24
- self
25
- end
26
-
27
- # Input:
28
- #
29
- # name = String | Symbol
30
- # args = Array[...Object]
31
- # &block = Proc(*args)
32
- #
33
- # Output: self
34
- def chain(name, *args, &block)
35
- validate_chain!(name, &block)
36
-
37
- @chain.push(
38
- [name, args, proc { |*all| @cache.with(name, *all, &block) }]
39
- )
40
-
41
- self
42
- end
43
-
44
- # Input:
45
- #
46
- # name = String | Symbol
47
- # args = Array[...Object]
48
- # &block = Proc(Hash{...Object => Object}, *args)
49
- #
50
- # Output: self
51
- def chain_many(name, *args, &block)
52
- validate_chain!(name, &block)
53
-
54
- @chain.push(
55
- [name, args, proc { |*all| @cache.with_many(name, *all, &block) }]
56
- )
57
-
58
- self
59
- end
60
-
61
- # Input:
62
- #
63
- # all = nil | :all # Default: nil
64
- #
65
- # Output: Object # Anything the last block in the chain returns.
66
- def run!(all = nil)
67
- validate_run!(all)
68
-
69
- if all
70
- run_all
71
- else
72
- run_chain
73
- end
74
- end
75
-
76
- # Output: self
77
- def expire!
78
- @cache.expire!
79
-
80
- self
81
- end
82
-
83
- # Input:
84
- #
85
- # names = ...(String | Symbol)
86
- #
87
- # Output: self
88
- def expire(*names)
89
- names.each do |name|
90
- @cache.expire(name)
91
- end
92
-
93
- self
94
- end
95
-
96
- private
97
-
98
- # Input:
99
- #
100
- # name = String | Symbol
101
- # &block = Proc
102
- #
103
- # Output: N/A
104
- def validate_chain!(name, &block)
105
- unless name.is_a?(Symbol) || name.is_a?(String)
106
- klass = name.class
107
- value = name.inspect
108
-
109
- raise(
110
- ArgumentError,
111
- "name must be a Symbol or a String, got #{klass}: #{value}"
112
- )
113
- end
114
-
115
- return unless block.nil?
116
-
117
- raise(
118
- ArgumentError,
119
- 'The `#chain/2` method needs to be called with a block'
120
- )
121
- end
122
-
123
- # Input:
124
- #
125
- # arg = nil | :all
126
- #
127
- # Output: N/A
128
- def validate_run!(arg)
129
- return if arg.nil? || arg == :all
130
-
131
- klass = arg.class
132
- value = arg.inspect
133
-
134
- raise(
135
- ArgumentError,
136
- 'The `run!` method only accepts `nil` or the Symbol `:all` as an ' \
137
- "argument, got #{klass}: #{value}"
138
- )
139
- end
140
-
141
- # Output: Object # Anything the last callable returns.
142
- def run_all
143
- result = nil
144
- @chain.each do |_name, args, callable|
145
- input = []
146
- input << result if result
147
- input += args if args
148
-
149
- result = callable.call(*input)
150
- end
151
-
152
- result
153
- end
154
-
155
- # Output: Object # Anything the last executed callable returns.
156
- def run_chain
157
- work = []
158
-
159
- @chain.reverse_each do |name, args, callable|
160
- work.push([name, args, callable])
161
-
162
- break if @cache.has?(name)
163
- end
164
-
165
- result = nil
166
- work.reverse_each do |_name, args, callable|
167
- input = []
168
- input << result if result
169
- input += args if args
170
-
171
- result = callable.call(*input)
172
- end
173
-
174
- result
175
- end
176
- end
177
- end