Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sr/make gridfs optional #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ Or, in Rails you can add it to your Gemfile:
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
```

Note: If using Rails 4, you'll need to make sure `mongoid-grid_fs` is `>= 1.9.0`.
If in doubt, run `bundle update mongoid-grid_fs`
Note: `mongoid-grid_fs` is no longer a runtime dependency. If you want to use
GridFS storage, you'll need to make sure `mongoid-grid_fs` is in your Gemfile
and uses version `>= 1.9.0`:

```ruby
gem 'mongoid-grid_fs', github: 'ahoward/mongoid-grid_fs'
gem 'mongoid-grid_fs', '>= 1.9.0'
```

## Getting Started
Expand All @@ -52,6 +53,10 @@ u.save!

## Using MongoDB's GridFS store

Add `mongoid-grid_fs` to your Gemfile and

require 'carrierwave/storage/grid_fs'

In your uploader, set the storage to `:grid_fs`:

```ruby
Expand All @@ -65,6 +70,8 @@ database connection and default all storage to GridFS. That might look something
like this:

```ruby
require 'carrierwave/storage/grid_fs'

CarrierWave.configure do |config|
config.storage = :grid_fs
config.root = Rails.root.join('tmp')
Expand Down Expand Up @@ -151,6 +158,7 @@ match '/uploads/grid/user/avatar/:id/:filename' => 'gridfs#thumb_avatar', constr

| Version | Notes |
|-----------|---------------------------------------------------------------------------------|
| ~> 2.0.0 | ([compare][compare-2.0], [dependencies][deps-2.0]) GridFS is now optional |
| ~> 1.1.0 | ([compare][compare-1.1], [dependencies][deps-1.1]) Mongoid 7.0 support |
| ~> 1.0.0 | ([compare][compare-1.0], [dependencies][deps-1.0]) Carrierwave 1.x support |
| ~> 0.10.0 | ([compare][compare-0.10], [dependencies][deps-0.10]) Mongoid 6.0 support |
Expand All @@ -164,6 +172,7 @@ match '/uploads/grid/user/avatar/:id/:filename' => 'gridfs#thumb_avatar', constr
| ~> 0.2.0 | ([compare][compare-0.2], [dependencies][deps-0.2]) Rails >= 3.2, Mongoid ~> 2.0 |
| ~> 0.1.0 | ([compare][compare-0.1], [dependencies][deps-0.1]) Rails <= 3.1 |

[compare-2.0]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v1.3.0...v2.0.0
[compare-1.1]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v1.0.0...v1.1.0
[compare-1.0]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.10.0...v1.0.0
[compare-0.10]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.9.0...v0.10.0
Expand All @@ -177,6 +186,7 @@ match '/uploads/grid/user/avatar/:id/:filename' => 'gridfs#thumb_avatar', constr
[compare-0.2]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.1.7...v0.2.2
[compare-0.1]: https://github.com/carrierwaveuploader/carrierwave-mongoid/compare/v0.1.1...v0.1.7

[deps-1.1]: https://rubygems.org/gems/carrierwave-mongoid/versions/2.0.0
[deps-1.1]: https://rubygems.org/gems/carrierwave-mongoid/versions/1.1.0
[deps-1.0]: https://rubygems.org/gems/carrierwave-mongoid/versions/1.0.0
[deps-0.10]: https://rubygems.org/gems/carrierwave-mongoid/versions/0.10.0
Expand Down
4 changes: 3 additions & 1 deletion carrierwave-mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ Gem::Specification.new do |s|

s.add_dependency "carrierwave", [">= 0.8", "< 3"]
s.add_dependency "mongoid", [">= 3.0", "< 8.0"]
s.add_dependency "mongoid-grid_fs", [">= 1.3", "< 3.0"]
s.add_dependency "mime-types", "< 3" if RUBY_VERSION < "2.0" # mime-types 3+ doesn't support ruby 1.9
if ENV['WITH_GRIDFS'] == 'true'
s.add_development_dependency "mongoid-grid_fs", [">= 1.3", "< 3.0"]
end
s.add_development_dependency "rspec", "~>3.4.0"
s.add_development_dependency "rake", "~>11.1.2"
s.add_development_dependency "mini_magick"
Expand Down
11 changes: 0 additions & 11 deletions lib/carrierwave/mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8

require 'mongoid'
require 'mongoid-grid_fs'
require 'carrierwave'
require 'carrierwave/validations/active_model'

Expand Down Expand Up @@ -146,14 +145,4 @@ def serializable_hash(options=nil)
end # Mongoid
end # CarrierWave

CarrierWave::Storage.autoload :GridFS, 'carrierwave/storage/grid_fs'

class CarrierWave::Uploader::Base
add_config :grid_fs_access_url

configure do |config|
config.storage_engines[:grid_fs] = "CarrierWave::Storage::GridFS"
end
end

Mongoid::Document::ClassMethods.send(:include, CarrierWave::Mongoid)
2 changes: 1 addition & 1 deletion lib/carrierwave/mongoid/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Carrierwave
module Mongoid
VERSION = "1.3.0"
VERSION = "2.0.0"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how you guys would want to handle a version update, as part of this PR or separately. Also not sure about the target version number. As I understand semver, a major version bump would be in order due to the backwards incompatible change.

end
end
8 changes: 8 additions & 0 deletions lib/carrierwave/storage/grid_fs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,11 @@ def clean_cache!(seconds)
end # GridFS
end # Storage
end # CarrierWave

class CarrierWave::Uploader::Base
add_config :grid_fs_access_url

configure do |config|
config.storage_engines[:grid_fs] = "CarrierWave::Storage::GridFS"
end
end
8 changes: 7 additions & 1 deletion spec/storage/grid_fs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@

end

describe CarrierWave::Storage::GridFS do
describe 'CarrierWave::Storage::GridFS' do
before(:context) do
skip unless ENV['WITH_GRIDFS'] == 'true'

require 'mongoid-grid_fs'
require 'carrierwave/storage/grid_fs'
end

before do
@uploader = double('an uploader')
Expand Down