paperclip-gridfs 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,13 +1,15 @@
1
1
  paperclip-gridfs
2
2
  ================
3
3
 
4
- A fork of gmontard/paperclip-gridfs (which was apparently a fork of kristianmandrup/paperclip), however no fork reference was wanted to thoughtbot/paperclip
4
+ A rewrite of gmontard/paperclip-gridfs, made to work as a real plugin, packaged as a gem and updated to work with the current mongo gem version. It brings GridFS support to [Paperclip](https://github.com/thoughtbot/paperclip) and supports plain Mongo, but it can also be used in complement with any ORM gem, like MongoMapper or Mongoid.
5
5
 
6
6
  ## Usage
7
7
 
8
+ The following examples are for MongoMapper, but the procedure should be similar to any other mongo ORM gem.
9
+
8
10
  There are two ways of configuring the GridFS connection. Either you create a connection or you reuse an existing connection.
9
11
 
10
- Creating a connection looks something like this:
12
+ Creating a connection looks something like this: you pass in `:storage => :gridfs`, along with a `:gridfs => {}` hash which includes the options.
11
13
 
12
14
  class User
13
15
  include MongoMapper::Document
@@ -18,7 +20,9 @@ Creating a connection looks something like this:
18
20
  has_attached_file :avatar, :storage => :gridfs, :gridfs => {:database => 'avatars', :host => 'test.com'}, :path => "avatars/:style/:filename", :url => "/avatars/:style/:filename"
19
21
  end
20
22
 
21
- When you already have a Mongo connection object (for example through Mongoid or MongoMapper) you can also reuse this connection:
23
+ You can pass in the host, port, database, username and password settings for MongoDB, but the only required value is the database name. Any values you don't set will just get filled in with MongoDB's defaults. If you optionally pass in the username and password keys, the connection will also get authenticated.
24
+
25
+ When you already have a Mongo connection object (for example through Mongoid or MongoMapper) you can also just reuse this connection:
22
26
 
23
27
  class User
24
28
  include MongoMapper::Document
@@ -29,17 +33,11 @@ When you already have a Mongo connection object (for example through Mongoid or
29
33
  has_attached_file :avatar, :storage => :gridfs, :gridfs => {:database => MongoMapper.database}, :path => "avatars/:style/:filename", :url => "/avatars/:style/:filename"
30
34
  end
31
35
 
32
- However, one then needs to also tie the URL's inside the app with the GridFS attachments (which can be viewed with `.to_file(style)`, outputting the binary contents, same as File.read). An example done in Sinatra, for the above class:
36
+ However, as the files stored inside GridFS are stored in a database, rather than the filesystem, you will need to work out a way to serve these files over HTTP. You can use a helper method, `.to_file(style)`, which returns the attachment0s binary contents. An example solution, done in Sinatra, for the above examples:
33
37
 
34
38
  # Get user avatar
35
39
  get '/avatars/:style/:id.:extension' do
36
- if params[:id] != 'missing'
37
- u = User.first(:id => params[:id])
38
- content_type u.avatar.content_type
39
- u.avatar.to_file(params[:style])
40
- else
41
- content_type 'image/png'
42
- File.open('public/avatars/missing.png').read #haxx
43
- end
44
- end
45
-
40
+ user = User.first(:id => params[:id])
41
+ content_type user.avatar.content_type
42
+ user.avatar.to_file(params[:style])
43
+ end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module GridFS
3
- VERSION = "1.0" unless defined? Paperclip::GridFS::VERSION
3
+ VERSION = "1.1" unless defined? Paperclip::GridFS::VERSION
4
4
  end
5
5
  end
@@ -73,7 +73,7 @@ module Paperclip
73
73
 
74
74
  def get_database_connection creds
75
75
  return creds[:database] if creds[:database].is_a? Mongo::DB
76
- db = Mongo::Connection.new(creds[:host] || Mongo::Connection::DEFAULT_HOST, creds[:port] || Mongo::Connection::DEFAULT_PORT).db(creds[:database])
76
+ db = Mongo::MongoClient.new(creds[:host], creds[:port]).db(creds[:database])
77
77
  db.authenticate(creds[:username], creds[:password]) if creds[:username] && creds[:password]
78
78
  return db
79
79
  end
@@ -21,5 +21,5 @@ spec = Gem::Specification.new do |s|
21
21
  #s.rdoc_options << '--line-numbers' << '--inline-source'
22
22
 
23
23
  s.add_dependency 'paperclip'
24
- s.add_dependency 'mongo', '>=1.1.4'
24
+ s.add_dependency 'mongo', '>=1.8.0'
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-gridfs
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-26 00:00:00.000000000 Z
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: paperclip
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 1.1.4
37
+ version: 1.8.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: 1.1.4
45
+ version: 1.8.0
46
46
  description: Paperclip extension to make it support GridFS
47
47
  email: blaz.hrast@gmail.com
48
48
  executables: []