refile-memory 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: edf99ee6da508219eafbbcbc063fc4746fee1282
4
+ data.tar.gz: bba409b91e1dfb367a79a89583ebdbf0e22cf270
5
+ SHA512:
6
+ metadata.gz: 7740ace89d6a2e5d657a7a112db9bdd060b52b1cc627ee06a54d8c2405a3dd8e11116da0954c16568f9c383d2e9d87c7ddffd9fcf3f2534d2a647b76c7cb9520
7
+ data.tar.gz: 7159e4522bafe51a929b9eab3b39814939842cf12fac5980689088de2b9dceebd9dfad24fd0af753a2f9c90dd8d884130ee5d3cf0e91bd07cb3a273a26421e05
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in refile-memory.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jonas Nicklas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Refile::Memory
2
+
3
+ An in-memory backend for [Refile](https://github.com/elabs/refile).
4
+
5
+ This probably isn't super useful, but it serves as an illustration on how to
6
+ write backends for Refile.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'refile-memory'
14
+ ```
15
+
16
+ Set up Refile to use the memory backend:
17
+
18
+ ``` ruby
19
+ Refile.configure do |config|
20
+ config.cache = Refile::Memory::Backend.new
21
+ config.store = Refile::Memory::Backend.new
22
+ end
23
+ ```
24
+
25
+ ## License
26
+
27
+ [MIT](License.txt)
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,55 @@
1
+ require "refile"
2
+ require "refile/memory/version"
3
+
4
+ module Refile
5
+ module Memory
6
+ class Backend
7
+ attr_reader :directory
8
+
9
+ def initialize(max_size: nil, hasher: Refile::RandomHasher.new)
10
+ @hasher = hasher
11
+ @max_size = max_size
12
+ @store = {}
13
+ end
14
+
15
+ def upload(uploadable)
16
+ Refile.verify_uploadable(uploadable, @max_size)
17
+
18
+ id = @hasher.hash(uploadable)
19
+
20
+ @store[id] = uploadable.read
21
+
22
+ Refile::File.new(self, id)
23
+ end
24
+
25
+ def get(id)
26
+ Refile::File.new(self, id)
27
+ end
28
+
29
+ def delete(id)
30
+ @store.delete(id)
31
+ end
32
+
33
+ def open(id)
34
+ StringIO.new(@store[id])
35
+ end
36
+
37
+ def read(id)
38
+ @store[id]
39
+ end
40
+
41
+ def size(id)
42
+ @store[id].bytesize if exists?(id)
43
+ end
44
+
45
+ def exists?(id)
46
+ @store.has_key?(id)
47
+ end
48
+
49
+ def clear!(confirm = nil)
50
+ raise ArgumentError, "are you sure? this will remove all files in the backend, call as `clear!(:confirm)` if you're sure you want to do this" unless confirm == :confirm
51
+ @store = {}
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ module Refile
2
+ module Memory
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'refile/memory/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "refile-memory"
8
+ spec.version = Refile::Memory::VERSION
9
+ spec.authors = ["Jonas Nicklas"]
10
+ spec.email = ["jonas.nicklas@gmail.com"]
11
+ spec.summary = %q{In memory backend for Refile}
12
+ spec.homepage = ""
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+
21
+ spec.add_dependency "refile"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ end
@@ -0,0 +1,9 @@
1
+ require "refile/memory"
2
+ require "refile/spec_helper"
3
+
4
+ RSpec.describe Refile::Memory::Backend do
5
+ let(:backend) { Refile::Memory::Backend.new(max_size: 100) }
6
+
7
+ it_behaves_like :backend
8
+ end
9
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refile-memory
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Nicklas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: refile
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - jonas.nicklas@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/refile/memory.rb
82
+ - lib/refile/memory/version.rb
83
+ - refile-memory.gemspec
84
+ - spec/refile/memory_spec.rb
85
+ homepage: ''
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.4.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: In memory backend for Refile
109
+ test_files:
110
+ - spec/refile/memory_spec.rb