activestorage-memory 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +19 -7
- data/activestorage-memory.gemspec +1 -1
- data/lib/active_storage/memory/version.rb +1 -1
- data/lib/active_storage/service/memory_service.rb +24 -7
- 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: 768576d7f8ddab4a37c7d7926ff3ac799328f45030481cede0b0a58ea2e53d95
|
4
|
+
data.tar.gz: 0af1f72600a0f6ba8b72448f5e2375d6439b5398235d9f9f4a0a9ec9d86cbdf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0bc9b5759bf76f16ecb8d52f29b8a1daacdb32464030d1e9529d49629f6ef7a1ba177172608738d578df792a99027ac24cf657994e44c2b45df557f8fd4451e3
|
7
|
+
data.tar.gz: afdccf65c826b80d12b322aafc364b602afd702e5527d6aa14be40628f81fc109bbf676dd8293bdcc16309e83366b723fb3fc1e7d2b70b580a545af522493063
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
# ActiveStorage
|
1
|
+
# ActiveStorage-Memory
|
2
2
|
|
3
|
-
|
3
|
+
Provides an in-memory ActiveStorage service.
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -22,13 +21,26 @@ Or install it yourself as:
|
|
22
21
|
|
23
22
|
## Usage
|
24
23
|
|
25
|
-
|
24
|
+
Declare a Memory service in config/storage.yml
|
26
25
|
|
27
|
-
|
26
|
+
```
|
27
|
+
memory:
|
28
|
+
service: Memory
|
29
|
+
```
|
30
|
+
|
31
|
+
To use the Memory service in test, you add the following to config/environments/test.rb:
|
32
|
+
|
33
|
+
```
|
34
|
+
config.active_storage.service = :memory
|
35
|
+
```
|
36
|
+
|
37
|
+
In Active Storage's analyzer feature, asynchronous jobs are executed. So it is recommended to set the queue adapter to async for test.
|
38
|
+
```
|
39
|
+
config.active_job.queue_adapter = :async
|
40
|
+
```
|
28
41
|
|
29
|
-
|
42
|
+
You can read more about Active Storage in the Active Storage Overview guide.
|
30
43
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
44
|
|
33
45
|
## Contributing
|
34
46
|
|
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['kykt35']
|
9
9
|
spec.email = ['kykt35@gmail.com']
|
10
10
|
|
11
|
-
spec.summary = 'Rails ActiveStorage in-memory
|
11
|
+
spec.summary = 'Rails ActiveStorage in-memory service adopter.'
|
12
12
|
spec.homepage = 'https://github.com/kykt35/activestorage-memory'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
@@ -17,13 +17,19 @@ module ActiveStorage
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def download(key)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
def download(key, &block)
|
21
|
+
if block_given?
|
22
|
+
instrument(:streaming_download, key: key) do
|
23
|
+
stream key, &block
|
24
|
+
end
|
25
|
+
else
|
26
|
+
instrument(:download, key: key) do
|
27
|
+
io = StringIO.new(store.fetch(key))
|
28
|
+
io.set_encoding(io.string.encoding)
|
29
|
+
io
|
30
|
+
rescue KeyError
|
31
|
+
raise ActiveStorage::FileNotFoundError
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
@@ -49,5 +55,16 @@ module ActiveStorage
|
|
49
55
|
"memory://#{key}"
|
50
56
|
end
|
51
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def stream(key)
|
62
|
+
io = StringIO.new(store.fetch(key))
|
63
|
+
while data = io.read(5.megabytes)
|
64
|
+
yield data
|
65
|
+
end
|
66
|
+
rescue KeyError
|
67
|
+
raise ActiveStorage::FileNotFoundError
|
68
|
+
end
|
52
69
|
end
|
53
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activestorage-memory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kykt35
|
@@ -90,5 +90,5 @@ requirements: []
|
|
90
90
|
rubygems_version: 3.4.10
|
91
91
|
signing_key:
|
92
92
|
specification_version: 4
|
93
|
-
summary: Rails ActiveStorage in-memory
|
93
|
+
summary: Rails ActiveStorage in-memory service adopter.
|
94
94
|
test_files: []
|