Skip to content

Commit

Permalink
Merge branch 'master' into switch-to-image_processing
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Mar 30, 2019
2 parents 4a64df3 + 5faff42 commit a6e0348
Show file tree
Hide file tree
Showing 29 changed files with 452 additions and 420 deletions.
62 changes: 24 additions & 38 deletions .travis.yml
Expand Up @@ -3,63 +3,49 @@ language: ruby
cache: bundler

rvm:
- 2.2.9
- 2.3.6
- 2.4.3
- jruby-9.1.15.0
- 2.5.5
- 2.6.2
- jruby-9.2.5.0

gemfile:
- gemfiles/rails-4-0.gemfile
- gemfiles/rails-4-1.gemfile
- gemfiles/rails-4-2.gemfile
- gemfiles/rails-5-0.gemfile
- gemfiles/rails-5-1.gemfile
- gemfiles/rails-master.gemfile
- gemfiles/rails-5-2.gemfile
- gemfiles/rails-6-0.gemfile

sudo: false

before_install:
#- gem update bundler
# https://github.com/danmayer/coverband/issues/162#issuecomment-452173268
- rm /home/travis/.rvm/gems/*/specifications/bundler-2.*.gemspec || true
- gem install bundler -v '<2'

before_script:
- psql -c 'create database carrierwave_test;' -U postgres

matrix:
include:
- rvm: 2.0
gemfile: gemfiles/rails-4-0.gemfile
- rvm: 2.0
gemfile: gemfiles/rails-4-1.gemfile
- rvm: 2.0
gemfile: gemfiles/rails-4-2.gemfile
- rvm: 2.1.10
gemfile: gemfiles/rails-4-0.gemfile
- rvm: 2.1.10
gemfile: gemfiles/rails-4-1.gemfile
- rvm: 2.1.10
gemfile: gemfiles/rails-4-2.gemfile
- rvm: ruby-head
- rvm: 2.2.10
gemfile: gemfiles/rails-5-2.gemfile
- rvm: 2.3.8
gemfile: gemfiles/rails-5-2.gemfile
- rvm: 2.4.5
gemfile: gemfiles/rails-5-2.gemfile
- rvm: 2.5.5
gemfile: gemfiles/rails-5-0.gemfile
- rvm: 2.5.5
gemfile: gemfiles/rails-5-1.gemfile
- rvm: ruby-head
- rvm: 2.6.2
gemfile: gemfiles/rails-master.gemfile
- rvm: ruby-head
gemfile: gemfiles/rails-6-0.gemfile
- rvm: jruby-head
gemfile: gemfiles/rails-5-1.gemfile
- rvm: jruby-head
gemfile: gemfiles/rails-master.gemfile
gemfile: gemfiles/rails-5-2.gemfile
exclude:
- rvm: 2.4.3
gemfile: gemfiles/rails-4-0.gemfile
- rvm: 2.4.3
gemfile: gemfiles/rails-4-1.gemfile
- rvm: 2.4.3
gemfile: gemfiles/rails-4-2.gemfile
- rvm: jruby-9.2.5.0
gemfile: gemfiles/rails-6-0.gemfile
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
- rvm: jruby-9.1.15.0
gemfile: gemfiles/rails-5-1.gemfile
- rvm: jruby-9.1.15.0
gemfile: gemfiles/rails-master.gemfile
- gemfile: gemfiles/rails-master.gemfile
fast_finish: true

notifications:
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,26 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## 1.3.1 - 2018-12-29
### Fixed
* Fix `#url_options_supported?` causing nil error(@mshibuya [0b9a64a1](https://github.com/carrierwaveuploader/carrierwave/commit/0b9a64a1bb9f20d1de154dc3bf2e2dd988210220), [#2361](https://github.com/carrierwaveuploader/carrierwave/issues/2361))

## 1.3.0 - 2018-12-24
### Added
* Query parameter support for fog-google(@stanhu [#2332](https://github.com/carrierwaveuploader/carrierwave/pull/2332))
* Jets Turbine Support(@tongueroo [#2355](https://github.com/carrierwaveuploader/carrierwave/pull/2355))
* Add `allowed_types` to `content_type_whitelist_error`(@mhluska [#2270](https://github.com/carrierwaveuploader/carrierwave/pull/2270))

### Fixed
* S3 HTTPS url causes certificate issue when bucket name contains period(@ransombriggs [#2359](https://github.com/carrierwaveuploader/carrierwave/pull/2359))
* Failed to get image dimensions when image is cached but not stored yet(@artygus [#2349](https://github.com/carrierwaveuploader/carrierwave/pull/2349))
* Only include `x-amz-acl` header for AWS(@stanhu [#2356](https://github.com/carrierwaveuploader/carrierwave/pull/2356))
* Remove old caches when no space is left on disk(@dosuken123 [#2342](https://github.com/carrierwaveuploader/carrierwave/pull/2342))

## 1.2.3 - 2018-06-30
### Fixed
* Fix reading whole content of large files into memory on storing(@dosuken123 [#2314](https://github.com/carrierwaveuploader/carrierwave/pull/2314))

## 1.2.2 - 2018-01-02
### Fixed
* Reset Content-Type on converting file format(@kyoshidajp [#2237](https://github.com/carrierwaveuploader/carrierwave/pull/2237))
Expand Down
26 changes: 16 additions & 10 deletions README.md
Expand Up @@ -4,8 +4,8 @@ This gem provides a simple and extremely flexible way to upload files from Ruby
It works well with Rack based web applications, such as Ruby on Rails.

[![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.svg?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave)
[![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
[![git.legal](https://git.legal/projects/1363/badge.svg "Number of libraries approved")](https://git.legal/projects/1363)
[![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)


## Information
Expand Down Expand Up @@ -89,7 +89,7 @@ a migration:


rails g migration add_avatar_to_users avatar:string
rake db:migrate
rails db:migrate

Open your model file and mount the uploader:

Expand Down Expand Up @@ -144,12 +144,12 @@ example, create a migration like this:
#### For databases with ActiveRecord json data type support (e.g. PostgreSQL, MySQL)

rails g migration add_avatars_to_users avatars:json
rake db:migrate
rails db:migrate

#### For database without ActiveRecord json data type support (e.g. SQLite)

rails g migration add_avatars_to_users avatars:string
rake db:migrate
rails db:migrate

__Note__: JSON datatype doesn't exists in SQLite adapter, that's why you can use a string datatype which will be serialized in model.

Expand All @@ -163,6 +163,9 @@ class User < ActiveRecord::Base
end
```

Make sure that you mount the uploader with write (mount_uploaders) with `s` not (mount_uploader)
in order to avoid errors when uploading multiple files

Make sure your file input fields are set up as multiple file fields. For
example in Rails you'll want to do something like this:

Expand Down Expand Up @@ -307,7 +310,7 @@ to exactly 200 by 200 pixels.

If you would like to crop images to a specific height and width you
can use the alternative option of '''resize_to_fill'''. It will make sure
that the width and height specified are filled, only cropping
that the width and height specified are filled, only cropping
if the aspect ratio requires it.

The uploader could be used like this:
Expand Down Expand Up @@ -633,6 +636,8 @@ describe MyUploader do
end
```

If you're looking for minitest asserts, checkout [carrierwave_asserts](https://github.com/hcfairbanks/carrierwave_asserts).

Setting the enable_processing flag on an uploader will prevent any of the versions from processing as well.
Processing can be enabled for a single version by setting the processing flag on the version like so:

Expand Down Expand Up @@ -667,13 +672,14 @@ CarrierWave.configure do |config|
config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: 'xxx', # required
aws_secret_access_key: 'yyy', # required
aws_access_key_id: 'xxx', # required unless using use_iam_profile
aws_secret_access_key: 'yyy', # required unless using use_iam_profile
use_iam_profile: true, # optional, defaults to false
region: 'eu-west-1', # optional, defaults to 'us-east-1'
host: 's3.example.com', # optional, defaults to nil
endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory = 'name_of_directory' # required
config.fog_directory = 'name_of_bucket' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
end
Expand Down Expand Up @@ -920,7 +926,7 @@ errors:
carrierwave_download_error: could not be downloaded
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
Expand Down
15 changes: 9 additions & 6 deletions carrierwave.gemspec
Expand Up @@ -19,25 +19,28 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.licenses = ["MIT"]

s.required_ruby_version = ">= 2.0.0"
s.required_ruby_version = ">= 2.2.2"

s.add_dependency "activesupport", ">= 4.0.0"
s.add_dependency "activemodel", ">= 4.0.0"
s.add_dependency "activesupport", ">= 5.0.0"
s.add_dependency "activemodel", ">= 5.0.0"
s.add_dependency "mime-types", ">= 1.16"
s.add_dependency "image_processing", "~> 1.1"
if RUBY_ENGINE == 'jruby'
s.add_development_dependency 'activerecord-jdbcpostgresql-adapter'
else
s.add_development_dependency "pg"
end
s.add_development_dependency "rails", ">= 4.0.0"
s.add_development_dependency "rails", ">= 5.0.0"
s.add_development_dependency "cucumber", "~> 2.3"
s.add_development_dependency "rspec", "~> 3.4"
s.add_development_dependency "webmock"
s.add_development_dependency "fog", ">= 1.28.0"
s.add_development_dependency "fog-aws"
s.add_development_dependency "fog-google", "~> 1.7"
s.add_development_dependency "fog-local"
s.add_development_dependency "fog-rackspace"
s.add_development_dependency "mini_magick", ">= 3.6.0"
if RUBY_ENGINE != 'jruby'
s.add_development_dependency "rmagick"
s.add_development_dependency "rmagick", "~> 2.16"
end
s.add_development_dependency "timecop"
s.add_development_dependency "generator_spec", ">= 0.9.1"
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/rails-4-0.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails-5-1.gemfile
Expand Up @@ -3,6 +3,6 @@ source "https://rubygems.org"
gem "rails", "~> 5.1.0"
gem "activemodel-serializers-xml"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platforms: :jruby
gem "activerecord-jdbcpostgresql-adapter", '~> 51.0', platforms: :jruby

gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails-4-1.gemfile → gemfiles/rails-5-2.gemfile
@@ -1,7 +1,7 @@
source "https://rubygems.org"

gem "rails", "~> 4.1.0"
gem "rails", "~> 5.2.0"
gem "activemodel-serializers-xml"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby

gemspec :path => "../"
4 changes: 2 additions & 2 deletions gemfiles/rails-4-2.gemfile → gemfiles/rails-6-0.gemfile
@@ -1,7 +1,7 @@
source "https://rubygems.org"

gem "rails", "~> 4.2.0"
gem "rails", "~> 6.0.0.beta3"
gem "activemodel-serializers-xml"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby

gemspec :path => "../"
2 changes: 1 addition & 1 deletion gemfiles/rails-master.gemfile
Expand Up @@ -7,6 +7,6 @@ gem "sprockets", github: "rails/sprockets", branch: "master"
gem "sprockets-rails", github: "rails/sprockets-rails", branch: "master"
gem "sass-rails", github: "rails/sass-rails"
gem "activemodel-serializers-xml"
gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platforms: :jruby
gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby

gemspec :path => "../"
20 changes: 20 additions & 0 deletions lib/carrierwave.rb
Expand Up @@ -34,6 +34,26 @@ def tmp_path
Dir.glob(File.join(Merb.load_paths[:uploaders])).each {|f| require f }
end

elsif defined?(Jets)

module CarrierWave
class Turbine < Jets::Turbine
initializer "carrierwave.setup_paths" do |app|
CarrierWave.root = Jets.root.to_s
CarrierWave.tmp_path = "/tmp/carrierwave"
CarrierWave.configure do |config|
config.cache_dir = "/tmp/carrierwave/uploads/tmp"
end
end

initializer "carrierwave.active_record" do
ActiveSupport.on_load :active_record do
require 'carrierwave/orm/activerecord'
end
end
end
end

elsif defined?(Rails)

module CarrierWave
Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/locale/en.yml
Expand Up @@ -6,7 +6,7 @@ en:
carrierwave_download_error: could not be downloaded
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files"
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
Expand Down
5 changes: 2 additions & 3 deletions lib/carrierwave/orm/activerecord.rb
Expand Up @@ -52,13 +52,12 @@ def mount_base(column, uploader=nil, options={}, &block)
validates_processing_of column if uploader_option(column.to_sym, :validate_processing)
validates_download_of column if uploader_option(column.to_sym, :validate_download)

after_save :"store_#{column}!"
before_save :"write_#{column}_identifier"
after_save :"store_previous_changes_for_#{column}"
after_commit :"remove_#{column}!", :on => :destroy
after_commit :"mark_remove_#{column}_false", :on => :update

after_save :"store_previous_changes_for_#{column}"
after_commit :"remove_previously_stored_#{column}", :on => :update
after_commit :"store_#{column}!", :on => [:create, :update]

class_eval <<-RUBY, __FILE__, __LINE__+1
def #{column}=(new_file)
Expand Down
6 changes: 1 addition & 5 deletions lib/carrierwave/processing/mini_magick.rb
Expand Up @@ -324,11 +324,7 @@ def resolve_dimensions(*dimensions)
end

def mini_magick_image
if url
::MiniMagick::Image.open(url)
else
::MiniMagick::Image.new(current_path)
end
::MiniMagick::Image.read(read)
end

end # MiniMagick
Expand Down
11 changes: 5 additions & 6 deletions lib/carrierwave/sanitized_file.rb
Expand Up @@ -114,12 +114,11 @@ def size
# [String, nil] the path where the file is located.
#
def path
unless @file.blank?
if is_path?
File.expand_path(@file)
elsif @file.respond_to?(:path) and not @file.path.blank?
File.expand_path(@file.path)
end
return if @file.blank?
if is_path?
File.expand_path(@file)
elsif @file.respond_to?(:path) && !@file.path.blank?
File.expand_path(@file.path)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/storage/file.rb
Expand Up @@ -66,7 +66,7 @@ def retrieve!(identifier)
#
def cache!(new_file)
new_file.move_to(::File.expand_path(uploader.cache_path, uploader.root), uploader.permissions, uploader.directory_permissions, true)
rescue Errno::EMLINK => e
rescue Errno::EMLINK, Errno::ENOSPC => e
raise(e) if @cache_called
@cache_called = true

Expand Down

0 comments on commit a6e0348

Please sign in to comment.