leifcr-refile-fog 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +3 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +5 -0
- data/lib/refile/fog.rb +74 -0
- data/lib/refile/fog/version.rb +5 -0
- data/refile-fog.gemspec +25 -0
- data/spec/refile/fog_spec.rb +24 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 950f9ae8aec8f9c34f47045e29b79fecedfc6a5f
|
4
|
+
data.tar.gz: 6540cd4420120595c977bf15cbee5a68e6326345
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1320e51f061a38cd2b6f6cf2c4058117818ad73344f108f96cb8bf7f431b451d666f6a7ffc60ccad42546d6f9da5984e75179329e6f9f0480f2cd87b038a8532
|
7
|
+
data.tar.gz: 5b3ce42c340c15c9bad9a4ab9188356228e99385bcc580c83a7a123238b20643afbe69a4e5ceecbb67c8e87b895270099bd065218a8e1e4155f84ae07966b945
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Refile::Fog
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/refile/refile-fog.svg)](https://travis-ci.org/refile/refile-fog)
|
4
|
+
|
5
|
+
A backend for [Refile](https://github.com/elabs/refile) which provides storage
|
6
|
+
in multiple cloud storage services via the [Fog](https://github.com/fog/fog)
|
7
|
+
cloud services gem.
|
8
|
+
|
9
|
+
If you're looking for a backend for Amazon S3, please use Refile's build in S3
|
10
|
+
backend. It is far superior to using S3 via Fog.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'refile-fog'
|
18
|
+
```
|
19
|
+
|
20
|
+
You also need to add the storage provider you use.
|
21
|
+
|
22
|
+
Example for google storage:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'fog-google'
|
26
|
+
gem 'google-api-client', '~> 0.8.6'
|
27
|
+
|
28
|
+
```
|
29
|
+
|
30
|
+
Set up Refile to use the fog backend:
|
31
|
+
|
32
|
+
``` ruby
|
33
|
+
# config/initializers/refile.rb
|
34
|
+
|
35
|
+
require "fog/google"
|
36
|
+
require "refile/fog"
|
37
|
+
|
38
|
+
credentials = {
|
39
|
+
provider: "Google",
|
40
|
+
aws_access_key_id: "zyx",
|
41
|
+
aws_secret_access_key: "12345",
|
42
|
+
directory: "my-app"
|
43
|
+
}
|
44
|
+
|
45
|
+
Refile.configure do |config|
|
46
|
+
config.cache = Refile::Fog::Backend.new(prefix: "cache", **credentials)
|
47
|
+
config.store = Refile::Fog::Backend.new(prefix: "store", **credentials)
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
[MIT](License.txt)
|
data/Rakefile
ADDED
data/lib/refile/fog.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require "fog/core"
|
2
|
+
require "fog/json"
|
3
|
+
require "fog/xml"
|
4
|
+
require "refile"
|
5
|
+
require "refile/fog/version"
|
6
|
+
|
7
|
+
module Refile
|
8
|
+
module Fog
|
9
|
+
class Backend
|
10
|
+
extend Refile::BackendMacros
|
11
|
+
|
12
|
+
attr_reader :directory, :max_size
|
13
|
+
|
14
|
+
def initialize(directory:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, connection: nil, **options)
|
15
|
+
@connection = connection || ::Fog::Storage.new(options)
|
16
|
+
@prefix = prefix
|
17
|
+
@hasher = hasher
|
18
|
+
@max_size = max_size
|
19
|
+
|
20
|
+
@directory = @connection.directories.new(key: directory)
|
21
|
+
end
|
22
|
+
|
23
|
+
verify_uploadable def upload(uploadable)
|
24
|
+
id = @hasher.hash(uploadable)
|
25
|
+
|
26
|
+
@directory.files.create(key: path(id), body: uploadable.read)
|
27
|
+
|
28
|
+
Refile::File.new(self, id)
|
29
|
+
end
|
30
|
+
|
31
|
+
verify_id def get(id)
|
32
|
+
Refile::File.new(self, id)
|
33
|
+
end
|
34
|
+
|
35
|
+
verify_id def delete(id)
|
36
|
+
file = head(id)
|
37
|
+
file.destroy if file
|
38
|
+
end
|
39
|
+
|
40
|
+
verify_id def open(id)
|
41
|
+
StringIO.new(read(id))
|
42
|
+
end
|
43
|
+
|
44
|
+
verify_id def read(id)
|
45
|
+
file = @directory.files.get(path(id))
|
46
|
+
file.body if file
|
47
|
+
end
|
48
|
+
|
49
|
+
verify_id def size(id)
|
50
|
+
file = head(id)
|
51
|
+
file.content_length if file
|
52
|
+
end
|
53
|
+
|
54
|
+
verify_id def exists?(id)
|
55
|
+
!!head(id)
|
56
|
+
end
|
57
|
+
|
58
|
+
verify_id def head(id)
|
59
|
+
@directory.files.head(path(id))
|
60
|
+
end
|
61
|
+
|
62
|
+
def clear!(confirm = nil)
|
63
|
+
raise Refile::Confirm unless confirm == :confirm
|
64
|
+
@directory.files.select { |f| f.key.start_with?(@prefix.to_s) }.each(&:destroy)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
verify_id def path(id)
|
70
|
+
::File.join(*@prefix, id)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/refile-fog.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'refile/fog/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "leifcr-refile-fog"
|
8
|
+
spec.version = Refile::Fog::VERSION
|
9
|
+
spec.authors = ["Jonas Nicklas"]
|
10
|
+
spec.email = ["jonas.nicklas@gmail.com"]
|
11
|
+
spec.summary = %q{Fog 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
|
+
spec.add_dependency "refile"
|
21
|
+
spec.add_dependency("fog-core", "~> 1.42")
|
22
|
+
spec.add_dependency("fog-json")
|
23
|
+
spec.add_dependency("fog-xml", "~> 0.1.1")
|
24
|
+
spec.add_development_dependency("fog-aws")
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "pry"
|
2
|
+
require "fog/aws"
|
3
|
+
require "refile/fog"
|
4
|
+
require "refile/spec_helper"
|
5
|
+
|
6
|
+
Fog.mock!
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.before do
|
10
|
+
@connection = ::Fog::Storage.new(provider: "AWS", aws_access_key_id: "zyx", aws_secret_access_key: "abc421")
|
11
|
+
@connection.directories.create(key: "refile-fog-test")
|
12
|
+
end
|
13
|
+
|
14
|
+
config.after do
|
15
|
+
@connection.directories.get("refile-fog-test").files.each(&:destroy)
|
16
|
+
@connection.directories.get("refile-fog-test").destroy
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
RSpec.describe Refile::Fog::Backend do
|
21
|
+
let(:backend) { Refile::Fog::Backend.new(max_size: 100, prefix: "cache", connection: @connection, directory: "refile-fog-test") }
|
22
|
+
|
23
|
+
it_behaves_like :backend
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leifcr-refile-fog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonas Nicklas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-08 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: fog-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.42'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.42'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fog-json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: fog-xml
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.1.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.1.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: fog-aws
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- jonas.nicklas@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/refile/fog.rb
|
97
|
+
- lib/refile/fog/version.rb
|
98
|
+
- refile-fog.gemspec
|
99
|
+
- spec/refile/fog_spec.rb
|
100
|
+
homepage: ''
|
101
|
+
licenses:
|
102
|
+
- MIT
|
103
|
+
metadata: {}
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubyforge_project:
|
120
|
+
rubygems_version: 2.5.1
|
121
|
+
signing_key:
|
122
|
+
specification_version: 4
|
123
|
+
summary: Fog backend for Refile
|
124
|
+
test_files:
|
125
|
+
- spec/refile/fog_spec.rb
|