fog-gridfs 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.swp
4
+ *.swo
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fog-gridfs.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Jon Yurek
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,19 @@
1
+ # fog-gridfs
2
+
3
+ This is an experimental gem written to prove to myself that fog can be extended
4
+ in such a way as to incorporate non-cloud technologies well. This gem in VERY
5
+ incomplete and not terribly well tested. It passes the specs and at least works
6
+ for me, so there's that.
7
+
8
+ ## Use at your own risk.
9
+
10
+ It's a few hours' hacking and barely passes the minimal specs I've written for
11
+ it.
12
+
13
+ That said, if you think this is useful, by all means please fork, hack, and
14
+ give me pull requests. It would be awesome for this to one day be useful to
15
+ more people.
16
+
17
+ ## License
18
+
19
+ Written in 2012 by jyurek. Released under the MIT License.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/setup"
3
+ require "rspec/core/rake_task"
4
+
5
+ desc "Run specs"
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.pattern = 'spec/{**/*_spec.rb}'
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/fog-gridfs/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Jon Yurek"]
6
+ gem.email = ["jyurek@thoughtbot.com"]
7
+ gem.description = %q{Allows fog to use gridfs as a storage backend.}
8
+ gem.summary = %q{gridfs for fog}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "fog-gridfs"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Fog::Gridfs::VERSION
17
+
18
+ gem.add_dependency('fog')
19
+ gem.add_dependency('mongo')
20
+ gem.add_dependency('bson_ext')
21
+ gem.add_development_dependency('rake')
22
+ gem.add_development_dependency('rspec')
23
+ gem.add_development_dependency('simplecov')
24
+ gem.add_development_dependency('pry')
25
+ end
data/lib/fog-gridfs.rb ADDED
@@ -0,0 +1,24 @@
1
+ require "fog-gridfs/version"
2
+ require 'fog'
3
+
4
+ module Fog
5
+ module Storage
6
+
7
+ def self.new_with_gridfs(attributes)
8
+ duped_attributes = attributes.dup
9
+ provider = duped_attributes.delete(:provider)
10
+ if provider == :grid_fs
11
+ require 'fog-gridfs/gridfs/storage'
12
+ Fog::Storage::Gridfs.new(duped_attributes)
13
+ else
14
+ new_without_gridfs(attributes)
15
+ end
16
+ end
17
+
18
+ class << self
19
+ alias_method :new_without_gridfs, :new
20
+ alias_method :new, :new_with_gridfs
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,21 @@
1
+ require 'fog/core/collection'
2
+ require 'fog-gridfs/gridfs/models/storage/directory'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Gridfs
7
+ class Directories < Fog::Collection
8
+
9
+ model Fog::Storage::Gridfs::Directory
10
+
11
+ def all
12
+ end
13
+
14
+ def get(key)
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,36 @@
1
+ require 'fog/core/model'
2
+ require 'fog-gridfs/gridfs/models/storage/files'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Gridfs
7
+
8
+ class Directory < Fog::Model
9
+
10
+ identity :key
11
+
12
+ def destroy
13
+ requires :key
14
+ false
15
+ end
16
+
17
+ def files
18
+ @files ||= begin
19
+ Fog::Storage::Gridfs::Files.new(
20
+ :directory => self,
21
+ :connection => connection
22
+ )
23
+ end
24
+ end
25
+
26
+ def save
27
+ requires :key
28
+ true
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,57 @@
1
+ require 'fog/core/model'
2
+
3
+ module Fog
4
+ module Storage
5
+ class Gridfs
6
+
7
+ class File < Fog::Model
8
+
9
+ identity :key, :aliases => 'Key'
10
+
11
+ attribute :content_length, :aliases => 'Content-Length', :type => :integer
12
+ attribute :content_type, :aliases => 'Content-Type'
13
+ attribute :last_modified, :aliases => 'Last-Modified'
14
+ attribute :directory
15
+
16
+ def filename
17
+ requires :directory, :key
18
+ [directory.key, key].join("/")
19
+ end
20
+
21
+ def body
22
+ @body ||= read
23
+ end
24
+
25
+ def body=(new_body)
26
+ @body = new_body
27
+ end
28
+
29
+ def destroy
30
+ requires :directory, :key
31
+ end
32
+
33
+ def read
34
+ requires :directory, :key
35
+ connection.open(filename, "r").read
36
+ end
37
+
38
+ def save(options = {})
39
+ requires :body, :directory, :key
40
+ file = connection.open(filename, "w", safe: true)
41
+ begin
42
+ if body.respond_to?(:read)
43
+ while(data = body.read)
44
+ file.write(data)
45
+ end
46
+ else
47
+ file.write(body)
48
+ end
49
+ ensure
50
+ file.close
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,35 @@
1
+ require 'fog/core/collection'
2
+ require 'fog-gridfs/gridfs/models/storage/file'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Gridfs
7
+
8
+ class Files < Fog::Collection
9
+
10
+ attribute :directory
11
+
12
+ model Fog::Storage::Gridfs::File
13
+
14
+ def all
15
+ requires :directory
16
+ end
17
+
18
+ def get(key)
19
+ requires :directory
20
+ new(key: key).body
21
+ end
22
+
23
+ def head(key)
24
+ requires :directory
25
+ end
26
+
27
+ def new(attributes = {})
28
+ requires :directory
29
+ super({ :directory => directory }.merge!(attributes))
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
@@ -0,0 +1,49 @@
1
+ require 'fog/storage'
2
+ require 'mongo'
3
+
4
+ module Fog
5
+ module Storage
6
+ class Gridfs < Fog::Service
7
+
8
+ requires :host, :database
9
+ recognizes :username, :password, :port
10
+
11
+ model_path 'fog-gridfs/gridfs/models/storage'
12
+ collection :directories
13
+ model :directory
14
+ collection :files
15
+ model :file
16
+
17
+ class Mock
18
+
19
+ end
20
+
21
+ class Real
22
+
23
+ attr_reader :fs
24
+
25
+ def initialize(options = {})
26
+ host = options[:host]
27
+ port = options[:port] || Mongo::Connection::DEFAULT_PORT
28
+ database = options[:database]
29
+ username = options[:username]
30
+ password = options[:password]
31
+
32
+ @connection = Mongo::Connection.new(host, port)
33
+ @database = @connection.db(database)
34
+ if username
35
+ @database.authenticate(username, password)
36
+ end
37
+
38
+ @fs = Mongo::GridFileSystem.new(@database)
39
+ end
40
+
41
+ def open(*args)
42
+ @fs.open(*args)
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Fog
2
+ module Gridfs
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fog::Gridfs do
4
+ it 'can load the adapter with minimal arguments' do
5
+ storage = Fog::Storage.new(provider: :grid_fs, host: "localhost", database: "football")
6
+ end
7
+
8
+ xit 'can load the adapter with additional arguments' do
9
+ # Actually works, but creds are bad.
10
+ storage = Fog::Storage.new(
11
+ provider: :grid_fs,
12
+ host: "localhost",
13
+ port: 27017,
14
+ database: "football",
15
+ username: "username",
16
+ password: "password"
17
+ )
18
+ end
19
+
20
+ it 'can create a "bucket" with a file in it, then confirm it is there' do
21
+ storage = Fog::Storage.new(provider: :grid_fs, host: "localhost", database: "football")
22
+ bucket = storage.directories.create(key: "goalline")
23
+ file = bucket.files.new({
24
+ key: "touchdown.txt",
25
+ body: "This is not an image file."
26
+ })
27
+ file.save
28
+
29
+ reloaded_file = bucket.files.new(key: "touchdown.txt")
30
+ reloaded_file.body.should == "This is not an image file."
31
+ end
32
+
33
+ it 'can fetch the file with #get' do
34
+ storage = Fog::Storage.new(provider: :grid_fs, host: "localhost", database: "baseball")
35
+ bucket = storage.directories.new(key: "infield")
36
+ file_body = "Not a belly itcher. 0.51 ERA, so that's legit."
37
+ file = bucket.files.new({
38
+ key: "pitcher.txt",
39
+ body: file_body
40
+ })
41
+ file.save
42
+
43
+ bucket.files.get('pitcher.txt').should == file_body
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $LOAD_PATH << File.join(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'rspec'
6
+ require "simplecov"
7
+ require "pry"
8
+
9
+ require 'fog-gridfs'
10
+
11
+ Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }
12
+
13
+ RSpec.configure do |config|
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fog-gridfs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Yurek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fog
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongo
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bson_ext
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: pry
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Allows fog to use gridfs as a storage backend.
127
+ email:
128
+ - jyurek@thoughtbot.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - .gitignore
134
+ - Gemfile
135
+ - LICENSE
136
+ - README.md
137
+ - Rakefile
138
+ - fog-gridfs.gemspec
139
+ - lib/fog-gridfs.rb
140
+ - lib/fog-gridfs/gridfs/models/storage/directories.rb
141
+ - lib/fog-gridfs/gridfs/models/storage/directory.rb
142
+ - lib/fog-gridfs/gridfs/models/storage/file.rb
143
+ - lib/fog-gridfs/gridfs/models/storage/files.rb
144
+ - lib/fog-gridfs/gridfs/storage.rb
145
+ - lib/fog-gridfs/version.rb
146
+ - spec/acceptance/fog-gridfs_spec.rb
147
+ - spec/spec_helper.rb
148
+ homepage: ''
149
+ licenses: []
150
+ post_install_message:
151
+ rdoc_options: []
152
+ require_paths:
153
+ - lib
154
+ required_ruby_version: !ruby/object:Gem::Requirement
155
+ none: false
156
+ requirements:
157
+ - - ! '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ requirements: []
167
+ rubyforge_project:
168
+ rubygems_version: 1.8.24
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: gridfs for fog
172
+ test_files:
173
+ - spec/acceptance/fog-gridfs_spec.rb
174
+ - spec/spec_helper.rb
175
+ has_rdoc: