refile-fog 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7982eff12cc9e7ccb0d038a3d19ef8166d6068a3
4
+ data.tar.gz: 57207283e372b14ca314a0f8f874ad50557faa30
5
+ SHA512:
6
+ metadata.gz: e1450cecb7e1b9a660d400e3889701ccd81324b2510480d6d521eb5502c414e62f0412868eab8ef936c315691f830861c7535b36ea1326e9091a0fe0a4bb451a
7
+ data.tar.gz: 1a9fba2c232bdbe24628646a378595a2df0fb62a774dd5f580b88348ec3e8f648edfddd3273e934156ea051bdc9faada43f77cd217ee74667e638c38df873978
data/.gitignore ADDED
@@ -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,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem "refile", github: "elabs/refile"
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,42 @@
1
+ # Refile::Fog
2
+
3
+ [![Build Status](https://travis-ci.org/elabs/refile-fog.svg)](https://travis-ci.org/elabs/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
+ Set up Refile to use the fog backend:
21
+
22
+ ``` ruby
23
+ # config/initializers/refile.rb
24
+
25
+ require "refile/fog"
26
+
27
+ credentials = {
28
+ provider: "Google",
29
+ aws_access_key_id: "zyx",
30
+ aws_secret_access_key: "12345",
31
+ directory: "my-app"
32
+ }
33
+
34
+ Refile.configure do |config|
35
+ config.cache = Refile::Fog::Backend.new(prefix: "cache", **credentials)
36
+ config.store = Refile::Fog::Backend.new(prefix: "store", **credentials)
37
+ end
38
+ ```
39
+
40
+ ## License
41
+
42
+ [MIT](License.txt)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/refile/fog.rb ADDED
@@ -0,0 +1,72 @@
1
+ require "fog"
2
+ require "refile"
3
+ require "refile/fog/version"
4
+
5
+ module Refile
6
+ module Fog
7
+ class Backend
8
+ attr_reader :directory
9
+
10
+ def initialize(directory:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, connection: nil, **options)
11
+ @connection = connection || ::Fog::Storage.new(options)
12
+ @prefix = prefix
13
+ @hasher = hasher
14
+ @max_size = max_size
15
+
16
+ @directory = @connection.directories.new(key: directory)
17
+ end
18
+
19
+ def upload(uploadable)
20
+ Refile.verify_uploadable(uploadable, @max_size)
21
+
22
+ id = @hasher.hash(uploadable)
23
+
24
+ @directory.files.create(key: path(id), body: uploadable.read)
25
+
26
+ Refile::File.new(self, id)
27
+ end
28
+
29
+ def get(id)
30
+ Refile::File.new(self, id)
31
+ end
32
+
33
+ def delete(id)
34
+ file = head(id)
35
+ file.destroy if file
36
+ end
37
+
38
+ def open(id)
39
+ StringIO.new(read(id))
40
+ end
41
+
42
+ def read(id)
43
+ file = @directory.files.get(path(id))
44
+ file.body if file
45
+ end
46
+
47
+ def size(id)
48
+ file = head(id)
49
+ file.content_length if file
50
+ end
51
+
52
+ def exists?(id)
53
+ !!head(id)
54
+ end
55
+
56
+ def head(id)
57
+ @directory.files.head(path(id))
58
+ end
59
+
60
+ def clear!(confirm = nil)
61
+ 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
62
+ @directory.files.select { |f| f.key.start_with?(@prefix.to_s) }.each(&:destroy)
63
+ end
64
+
65
+ private
66
+
67
+ def path(id)
68
+ ::File.join(*@prefix, id)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Refile
2
+ module Fog
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
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 = "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
+
21
+ spec.add_dependency "refile"
22
+ spec.add_dependency "fog"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "pry"
28
+ end
@@ -0,0 +1,24 @@
1
+ require "pry"
2
+ require "refile/fog"
3
+ require "refile/spec_helper"
4
+
5
+ Fog.mock!
6
+
7
+ RSpec.configure do |config|
8
+ config.before do
9
+ @connection = ::Fog::Storage.new(provider: "AWS", aws_access_key_id: "zyx", aws_secret_access_key: "abc421")
10
+ @connection.directories.create(key: "refile-fog-test")
11
+ end
12
+
13
+ config.after do
14
+ @connection.directories.get("refile-fog-test").files.each(&:destroy)
15
+ @connection.directories.get("refile-fog-test").destroy
16
+ end
17
+ end
18
+
19
+ RSpec.describe Refile::Fog::Backend do
20
+ let(:backend) { Refile::Fog::Backend.new(max_size: 100, prefix: "cache", connection: @connection, directory: "refile-fog-test") }
21
+
22
+ it_behaves_like :backend
23
+ end
24
+
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refile-fog
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-12 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
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - jonas.nicklas@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - lib/refile/fog.rb
110
+ - lib/refile/fog/version.rb
111
+ - refile-fog.gemspec
112
+ - spec/refile/fog_spec.rb
113
+ homepage: ''
114
+ licenses:
115
+ - MIT
116
+ metadata: {}
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubyforge_project:
133
+ rubygems_version: 2.4.3
134
+ signing_key:
135
+ specification_version: 4
136
+ summary: Fog backend for Refile
137
+ test_files:
138
+ - spec/refile/fog_spec.rb