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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 225cd38418cfa2b7318059599b306cecb07a0a14f16673ab13468a261ca7c87d
4
- data.tar.gz: c96879c4425e6df7c435b52be5718187f8b5bf6cfba92131da1f6d5632cb3a01
3
+ metadata.gz: 768576d7f8ddab4a37c7d7926ff3ac799328f45030481cede0b0a58ea2e53d95
4
+ data.tar.gz: 0af1f72600a0f6ba8b72448f5e2375d6439b5398235d9f9f4a0a9ec9d86cbdf6
5
5
  SHA512:
6
- metadata.gz: 0a69efcb428a4a2b9fead9ee4d1c78427fcd6823e4314cb4a550c98ab05bf8fd88ebb476f9c90761f09b3b581cd5f7ed91d294112a897a8f94a81c4bf96cbeee
7
- data.tar.gz: bd0a3463ec6ad8d08b93c318a9f299610be8452d09f5b0ed862cd5417c0ffe33ee1210f4124997d7a049853b50d4821b2f66f007469a15b7bb5cb9481f5c7245
6
+ metadata.gz: 0bc9b5759bf76f16ecb8d52f29b8a1daacdb32464030d1e9529d49629f6ef7a1ba177172608738d578df792a99027ac24cf657994e44c2b45df557f8fd4451e3
7
+ data.tar.gz: afdccf65c826b80d12b322aafc364b602afd702e5527d6aa14be40628f81fc109bbf676dd8293bdcc16309e83366b723fb3fc1e7d2b70b580a545af522493063
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activestorage-memory (0.1.0)
4
+ activestorage-memory (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,8 +1,7 @@
1
- # ActiveStorage::Memory
1
+ # ActiveStorage-Memory
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/active_storage/memory`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
24
+ Declare a Memory service in config/storage.yml
26
25
 
27
- ## Development
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
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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 service adopter.'
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')
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveStorage
4
4
  module Memory
5
- VERSION = "0.1.0"
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
@@ -17,13 +17,19 @@ module ActiveStorage
17
17
  end
18
18
  end
19
19
 
20
- def download(key)
21
- instrument(:streaming_download, key: key) do
22
- io = StringIO.new(store.fetch(key))
23
- io.set_encoding(io.string.encoding)
24
- io
25
- rescue KeyError
26
- raise ActiveStorage::FileNotFoundError
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.0
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 service adopter.
93
+ summary: Rails ActiveStorage in-memory service adopter.
94
94
  test_files: []