shrine-memory 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +24 -0
- data/lib/shrine/storage/memory.rb +64 -0
- data/shrine-memory.gemspec +21 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3fd54c31c0af0cbc24bf2cc13ed31ddefa9d75c2
|
4
|
+
data.tar.gz: ac78c8c8b12aa63628a4be5b3ff3e792d8d50324
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fb572300024fd9f94df599628f91512d3ed65d0874d6727378c12399a5abaf73768c67859ed59fa246a78e16c3a2da44b4e66dce1c3b96849d30051ec14448ae
|
7
|
+
data.tar.gz: 1a66355aa04acceaa80af5e644342b431574b6c22da5094c94ea575fd415d13d1bd89cb0bab9d3c9fd188a9214ac0bc01d83b9918b534b5cb7f51695fa8d6d63
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Janko Marohnić
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Shrine::Storage::Memory
|
2
|
+
|
3
|
+
Provides in-memory storage for Shrine.
|
4
|
+
|
5
|
+
This storage generally shouldn't be used in real applications, but it is handy
|
6
|
+
for testing.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem "shrine-memory"
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
```rb
|
17
|
+
require "shrine/storage/memory"
|
18
|
+
|
19
|
+
Shrine.storages[:cache] = Shrine::Storage::Memory.new
|
20
|
+
```
|
21
|
+
|
22
|
+
## License
|
23
|
+
|
24
|
+
[MIT](/LICENSE.txt)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "shrine"
|
2
|
+
require "stringio"
|
3
|
+
require "down"
|
4
|
+
|
5
|
+
class Shrine
|
6
|
+
module Storage
|
7
|
+
class Memory
|
8
|
+
attr_reader :store
|
9
|
+
|
10
|
+
def initialize(store = {})
|
11
|
+
@store = store
|
12
|
+
end
|
13
|
+
|
14
|
+
def upload(io, id, *)
|
15
|
+
store[id] = io.read
|
16
|
+
end
|
17
|
+
|
18
|
+
def download(id)
|
19
|
+
Down.copy_to_tempfile(id, open(id))
|
20
|
+
end
|
21
|
+
|
22
|
+
def move(io, id, *)
|
23
|
+
store[id] = io.storage.delete(io.id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def movable?(io, id)
|
27
|
+
io.is_a?(UploadedFile) && io.storage.is_a?(Storage::Memory)
|
28
|
+
end
|
29
|
+
|
30
|
+
def stream(id)
|
31
|
+
yield read(id), read(id).length
|
32
|
+
end
|
33
|
+
|
34
|
+
def open(id)
|
35
|
+
StringIO.new(store.fetch(id))
|
36
|
+
end
|
37
|
+
|
38
|
+
def read(id)
|
39
|
+
store.fetch(id).dup
|
40
|
+
end
|
41
|
+
|
42
|
+
def exists?(id)
|
43
|
+
store.key?(id)
|
44
|
+
end
|
45
|
+
|
46
|
+
def delete(id)
|
47
|
+
store.delete(id) or raise KeyError, "key not found: #{id.inspect}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def multi_delete(ids)
|
51
|
+
ids.each { |id| delete(id) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def url(id, **options)
|
55
|
+
"memory://#{id}"
|
56
|
+
end
|
57
|
+
|
58
|
+
def clear!(confirm = nil)
|
59
|
+
raise Shrine::Confirm unless confirm == :confirm
|
60
|
+
store.clear
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Gem::Specification.new do |gem|
|
2
|
+
gem.name = "shrine-memory"
|
3
|
+
gem.version = "0.1.0"
|
4
|
+
|
5
|
+
gem.required_ruby_version = ">= 2.1"
|
6
|
+
|
7
|
+
gem.summary = "Provides in-memory storage for Shrine."
|
8
|
+
gem.homepage = "https://github.com/janko-m/shrine-memory"
|
9
|
+
gem.authors = ["Janko Marohnić"]
|
10
|
+
gem.email = ["janko.marohnic@gmail.com"]
|
11
|
+
gem.license = "MIT"
|
12
|
+
|
13
|
+
gem.files = Dir["README.md", "LICENSE.txt", "lib/**/*.rb", "*.gemspec"]
|
14
|
+
gem.require_path = "lib"
|
15
|
+
|
16
|
+
gem.add_dependency "shrine"
|
17
|
+
gem.add_dependency "down"
|
18
|
+
|
19
|
+
gem.add_development_dependency "rake"
|
20
|
+
gem.add_development_dependency "minitest"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shrine-memory
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Janko Marohnić
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: shrine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: down
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- janko.marohnic@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
- lib/shrine/storage/memory.rb
|
79
|
+
- shrine-memory.gemspec
|
80
|
+
homepage: https://github.com/janko-m/shrine-memory
|
81
|
+
licenses:
|
82
|
+
- MIT
|
83
|
+
metadata: {}
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '2.1'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
requirements: []
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 2.5.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: Provides in-memory storage for Shrine.
|
104
|
+
test_files: []
|
105
|
+
has_rdoc:
|