New upstream version 1.2.3

parent b2f9d1e5
......@@ -3,10 +3,11 @@ language: ruby
cache: bundler
rvm:
- 2.2.7
- 2.3.4
- 2.4.1
- jruby-9.1.5.0
- 2.2.10
- 2.3.7
- 2.4.4
- 2.5.1
- jruby-9.1.15.0
gemfile:
- gemfiles/rails-4-0.gemfile
......@@ -14,12 +15,12 @@ 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
sudo: false
before_install:
#- gem update bundler
- gem install bundler
before_script:
- psql -c 'create database carrierwave_test;' -U postgres
......@@ -32,33 +33,41 @@ matrix:
gemfile: gemfiles/rails-4-1.gemfile
- rvm: 2.0
gemfile: gemfiles/rails-4-2.gemfile
- rvm: 2.1
- rvm: 2.1.10
gemfile: gemfiles/rails-4-0.gemfile
- rvm: 2.1
- rvm: 2.1.10
gemfile: gemfiles/rails-4-1.gemfile
- rvm: 2.1
- rvm: 2.1.10
gemfile: gemfiles/rails-4-2.gemfile
- rvm: 2.5.1
gemfile: gemfiles/rails-master.gemfile
- rvm: ruby-head
gemfile: gemfiles/rails-5-1.gemfile
gemfile: gemfiles/rails-5-2.gemfile
- rvm: ruby-head
gemfile: gemfiles/rails-master.gemfile
- rvm: jruby-head
gemfile: gemfiles/rails-5-1.gemfile
gemfile: gemfiles/rails-5-0.gemfile
- rvm: jruby-head
gemfile: gemfiles/rails-master.gemfile
gemfile: gemfiles/rails-5-1.gemfile
exclude:
- rvm: 2.4.1
- rvm: 2.4.4
gemfile: gemfiles/rails-4-0.gemfile
- rvm: 2.4.1
- rvm: 2.4.4
gemfile: gemfiles/rails-4-1.gemfile
- rvm: 2.4.1
gemfile: gemfiles/rails-4-2.gemfile
- rvm: 2.5.1
gemfile: gemfiles/rails-4-0.gemfile
- rvm: 2.5.1
gemfile: gemfiles/rails-4-1.gemfile
- rvm: jruby-9.1.15.0
gemfile: gemfiles/rails-5-2.gemfile
allow_failures:
- rvm: ruby-head
- rvm: jruby-head
- gemfile: gemfiles/rails-master.gemfile
- rvm: jruby-9.1.5.0
- rvm: jruby-9.1.15.0
gemfile: gemfiles/rails-5-0.gemfile
- rvm: jruby-9.1.15.0
gemfile: gemfiles/rails-5-1.gemfile
- gemfile: gemfiles/rails-master.gemfile
fast_finish: true
notifications:
......
......@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
## 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))
......
source "https://rubygems.org"
gem "activemodel-serializers-xml"
gem 'pg', '~> 0.21.0', platforms: :ruby
gemspec
......@@ -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
......@@ -24,7 +24,7 @@ It works well with Rack based web applications, such as Ruby on Rails.
Install the latest release:
```
$ gem install carrierwave -v "1.0.0"
$ gem install carrierwave
```
In Rails, add it to your Gemfile:
......@@ -307,7 +307,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 copping
that the width and height specified are filled, only cropping
if the aspect ratio requires it.
The uploader could be used like this:
......@@ -633,6 +633,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:
......@@ -667,13 +669,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
......
......@@ -33,7 +33,10 @@ Gem::Specification.new do |s|
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", "<= 0.1.0"
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"
......
......@@ -2,6 +2,7 @@ source "https://rubygems.org"
gem "rails", "~> 4.0.0"
gem "railties", "~> 4.0.0"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby
gemspec :path => "../"
source "https://rubygems.org"
gem "rails", "~> 4.1.0"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby
gemspec :path => "../"
source "https://rubygems.org"
gem "rails", "~> 4.2.0"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3", platforms: :jruby
gemspec :path => "../"
source "https://rubygems.org"
gem "rails", "~> 5.0.0"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activemodel-serializers-xml"
gem "activerecord-jdbcpostgresql-adapter", "~> 50.0", platforms: :jruby
......
......@@ -2,6 +2,7 @@ source "https://rubygems.org"
gem "rails", "~> 5.1.0"
gem "activemodel-serializers-xml"
gem "activerecord-jdbcpostgresql-adapter", "~> 51.0", platforms: :jruby
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby
gemspec :path => "../"
source "https://rubygems.org"
gem "rails", "~> 5.2.0"
gem "activemodel-serializers-xml"
gem 'pg', '~> 0.21.0', platforms: :ruby
gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby
gemspec :path => "../"
......@@ -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", github: "jruby/activerecord-jdbc-adapter", branch: "rails-5", platforms: :jruby
gem "activerecord-jdbcpostgresql-adapter", github: "jruby/activerecord-jdbc-adapter", platforms: :jruby
gemspec :path => "../"
......@@ -61,6 +61,13 @@ module CarrierWave
e.message << " (You may need to install the mini_magick gem)"
raise e
end
prepend Module.new {
def initialize(*)
super
@format = nil
end
}
end
module ClassMethods
......
......@@ -67,6 +67,13 @@ module CarrierWave
e.message << " (You may need to install the rmagick gem)"
raise e
end
prepend Module.new {
def initialize(*)
super
@format = nil
end
}
end
module ClassMethods
......@@ -346,7 +353,7 @@ module CarrierWave
frames = ::Magick::ImageList.new
image.each_with_index do |frame, index|
frame = yield *[frame, index, options].take(block.arity) if block_given?
frame = yield(*[frame, index, options].take(block.arity)) if block_given?
frames << frame if frame
end
frames.append(true) if block_given?
......
......@@ -20,7 +20,7 @@ module CarrierWave
#
class SanitizedFile
attr_accessor :file
attr_reader :file
class << self
attr_writer :sanitize_regexp
......@@ -32,6 +32,7 @@ module CarrierWave
def initialize(file)
self.file = file
@content = nil
end
##
......
......@@ -7,6 +7,10 @@ module CarrierWave
# pretty much it.
#
class File < Abstract
def initialize(*)
super
@cache_called = nil
end
##
# Move the file to the uploader's store path.
......
......@@ -266,7 +266,7 @@ module CarrierWave
end
def initialize(uploader, base, path)
@uploader, @base, @path = uploader, base, path
@uploader, @base, @path, @content_type = uploader, base, path, nil
end
##
......@@ -276,6 +276,16 @@ module CarrierWave
#
# [String] contents of file
def read
file_body = file.body
return if file_body.nil?
return file_body unless file_body.is_a?(::File)
# Fog::Storage::XXX::File#body could return the source file which was upoloaded to the remote server.
read_source_file(file_body) if ::File.exist?(file_body.path)
# If the source file doesn't exist, the remote content is read
@file = nil # rubocop:disable Gitlab/ModuleWithInstanceVariables
file.body
end
......@@ -313,7 +323,7 @@ module CarrierWave
fog_file = new_file.to_file
@content_type ||= new_file.content_type
@file = directory.files.create({
:body => (fog_file ? fog_file : new_file).read,
:body => fog_file ? fog_file : new_file.read,
:content_type => @content_type,
:key => path,
:public => @uploader.fog_public
......@@ -458,6 +468,17 @@ module CarrierWave
def acl_header
{'x-amz-acl' => @uploader.fog_public ? 'public-read' : 'private'}
end
def read_source_file(file_body)
return unless ::File.exist?(file_body.path)
begin
file_body = ::File.open(file_body.path) if file_body.closed? # Reopen if it's already closed
file_body.read
ensure
file_body.close
end
end
end
end # Fog
......
......@@ -43,6 +43,15 @@ module CarrierWave
class Base
attr_reader :file
##
# Workaround for class_attribute malfunction when used with Module#prepend
#
if RUBY_VERSION < '2.1.0'
def self.singleton_class?
!ancestors.include? self
end
end
include CarrierWave::Uploader::Configuration
include CarrierWave::Uploader::Callbacks
include CarrierWave::Uploader::Proxy
......
......@@ -117,12 +117,14 @@ module CarrierWave
def add_config(name)
class_eval <<-RUBY, __FILE__, __LINE__ + 1
@#{name} = nil
def self.eager_load_fog(fog_credentials)
# see #1198. This will hopefully no longer be necessary after fog 2.0
require self.fog_provider
require 'carrierwave/storage/fog'
Fog::Storage.new(fog_credentials) if fog_credentials.present?
end
end unless defined? eager_load_fog
def self.#{name}(value=nil)
@#{name} = value if value
......
......@@ -13,6 +13,7 @@ module CarrierWave
def initialize(uri, remote_headers = {})
@uri = uri
@remote_headers = remote_headers
@file = nil
end
def original_filename
......
module CarrierWave
module Uploader
##
# This modules validates the content type of a file with the use of
# ruby-filemagic gem and a blacklist regular expression. If you want
# to use this, you'll need to require this file:
#
# require 'carrierwave/uploader/magic_mime_blacklist'
#
# And then include it in your uploader:
#
# class MyUploader < CarrierWave::Uploader::Base
# include CarrierWave::Uploader::MagicMimeBlacklist
#
# def blacklist_mime_type_pattern
# /image\//
# end
# end
#
module MagicMimeBlacklist
extend ActiveSupport::Concern
included do
begin
require "filemagic"
rescue LoadError => e
e.message << " (You may need to install the ruby-filemagic gem)"
raise e
end
before :cache, :check_blacklist_pattern!
end
##
# Override this method in your uploader to provide a black list pattern (regexp)
# of content-types which are prohibited to be uploaded.
# Compares the file's content-type.
#
# === Returns
#
# [Regexp] a black list regexp to match the content_type
#
# === Examples
#
# def blacklist_mime_type_pattern
# /(text|application)\/json/
# end
#
def blacklist_mime_type_pattern; end
private
def check_blacklist_pattern!(new_file)
return if blacklist_mime_type_pattern.nil?
content_type = extract_content_type(new_file)
if content_type.match(blacklist_mime_type_pattern)
raise CarrierWave::IntegrityError,
I18n.translate(:"errors.messages.mime_type_pattern_black_list_error",
:content_type => content_type)
end
end
##
# Extracts the content type of the given file
#
# === Returns
#
# [String] the extracted content type
#
def extract_content_type(new_file)
content_type = nil
File.open(new_file.path) do |fd|
data = fd.read(1024) || ""
content_type = filemagic.buffer(data)
end
content_type
end
##
# FileMagic object with the MAGIC_MIME_TYPE flag set
#
# @return [FileMagic] a filemagic object
def filemagic
@filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE)
end
end # MagicMimeblackList
end # Uploader
end # CarrierWave
module CarrierWave
module Uploader
##
# This modules validates the content type of a file with the use of
# ruby-filemagic gem and a whitelist regular expression. If you want
# to use this, you'll need to require this file:
#
# require 'carrierwave/uploader/magic_mime_whitelist'
#
# And then include it in your uploader:
#
# class MyUploader < CarrierWave::Uploader::Base
# include CarrierWave::Uploader::MagicMimeWhitelist
#
# def whitelist_mime_type_pattern
# /image\//
# end
# end
#
module MagicMimeWhitelist
extend ActiveSupport::Concern
included do
begin
require "filemagic"
rescue LoadError => e
e.message << " (You may need to install the ruby-filemagic gem)"
raise e
end
before :cache, :check_whitelist_pattern!
end
##
# Override this method in your uploader to provide a white list pattern (regexp)
# of content-types which are allowed to be uploaded.
# Compares the file's content-type.
#
# === Returns
#
# [Regexp] a white list regexp to match the content_type
#
# === Examples
#
# def whitelist_mime_type_pattern
# /(text|application)\/json/
# end
#
def whitelist_mime_type_pattern; end
private
def check_whitelist_pattern!(new_file)
return if whitelist_mime_type_pattern.nil?
content_type = extract_content_type(new_file)
if !content_type.match(whitelist_mime_type_pattern)
raise CarrierWave::IntegrityError,
I18n.translate(:"errors.messages.mime_type_pattern_white_list_error",
:content_type => content_type)
end
end
##
# Extracts the content type of the given file
#
# === Returns
#
# [String] the extracted content type
#
def extract_content_type(new_file)
content_type = nil
File.open(new_file.path) do |fd|
data = fd.read(1024) || ""
content_type = filemagic.buffer(data)
end
content_type
end
##
# FileMagic object with the MAGIC_MIME_TYPE flag set
#
# @return [FileMagic] a filemagic object
def filemagic
@filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE)
end
end # MagicMimeWhiteList
end # Uploader
end # CarrierWave
......@@ -7,6 +7,15 @@ module CarrierWave
include CarrierWave::Uploader::Configuration
include CarrierWave::Uploader::Cache
included do
prepend Module.new {
def initialize(*)
super
@file, @filename, @cache_id = nil
end
}
end
##
# Override this in your Uploader to change the filename.
#
......
......@@ -19,6 +19,13 @@ module CarrierWave
after :remove, :remove_versions!
after :retrieve_from_cache, :retrieve_versions_from_cache!
after :retrieve_from_store, :retrieve_versions_from_store!
prepend Module.new {
def initialize(*)
super
@versions = nil
end
}
end
module ClassMethods
......@@ -77,7 +84,7 @@ module CarrierWave
# value from the parent class unless explicitly overwritten
def self.enable_processing(value=nil)
self.enable_processing = value if value
if !@enable_processing.nil?
if defined?(@enable_processing) && !@enable_processing.nil?
@enable_processing
else
superclass.enable_processing
......
module CarrierWave
VERSION = "1.2.2"
VERSION = "1.2.3"
end
......@@ -74,6 +74,9 @@ module CarrierWave
def change_locale_and_store_translations(locale, translations, &block)
current_locale = I18n.locale
begin
# I18n.available_locales needs to be cleared before storing translations:
# https://github.com/svenfuchs/i18n/pull/391
I18n.available_locales = nil
I18n.backend.store_translations locale, translations
I18n.locale = locale
yield
......
This diff is collapsed.
require 'spec_helper'
require 'fog'
require 'fog/aws'
require 'fog/google'
require 'fog/local'
require 'fog/rackspace'
require 'carrierwave/storage/fog'
unless ENV['REMOTE'] == 'true'
......
......@@ -2,13 +2,17 @@ require 'spec_helper'
require 'carrierwave/storage/fog'
describe CarrierWave do
let(:uploader_class) { Class.new(CarrierWave::Uploader::Base) }
describe '.configure' do
before do
CarrierWave::Uploader::Base.add_config :test_config
CarrierWave.configure { |config| config.test_config = "foo" }
end
after do
CarrierWave::Uploader::Base.singleton_class.send :undef_method, :test_config
CarrierWave::Uploader::Base.singleton_class.send :undef_method, :test_config=
CarrierWave::Uploader::Base.send :undef_method, :test_config
CarrierWave::Uploader::Base.send :undef_method, :test_config=
end
it "proxies to Uploader configuration" do
expect(CarrierWave::Uploader::Base.test_config).to eq('foo')
......@@ -26,6 +30,12 @@ describe CarrierWave::Uploader::Base do
uc.configure { |config| config.foo_bar = "monkey" }
end
end
after do
uploader_class.singleton_class.send :undef_method, :foo_bar
uploader_class.singleton_class.send :undef_method, :foo_bar=
uploader_class.send :undef_method, :foo_bar
uploader_class.send :undef_method, :foo_bar=
end
it "sets a configuration parameter" do
expect(uploader_class.foo_bar).to eq('monkey')
......@@ -76,6 +86,12 @@ describe CarrierWave::Uploader::Base do
uploader_class.add_config :foo_bar
uploader_class.foo_bar = 'foo'
end
after do
uploader_class.singleton_class.send :undef_method, :foo_bar
uploader_class.singleton_class.send :undef_method, :foo_bar=
uploader_class.send :undef_method, :foo_bar
uploader_class.send :undef_method, :foo_bar=
end
it "adds a class level accessor" do
expect(uploader_class.foo_bar).to eq('foo')
......@@ -91,6 +107,11 @@ describe CarrierWave::Uploader::Base do
['foo', :foo, 45, ['foo', :bar]].each do |val|
it "'s inheritable for a #{val.class}" do
uploader_class.singleton_class.send :undef_method, :foo_bar
uploader_class.singleton_class.send :undef_method, :foo_bar=
uploader_class.send :undef_method, :foo_bar
uploader_class.send :undef_method, :foo_bar=
uploader_class.add_config :foo_bar
child_class = Class.new(uploader_class)
......@@ -112,6 +133,12 @@ describe CarrierWave::Uploader::Base do
uc.hoobatz = this_proc
end
end
after do
uploader_class.singleton_class.send :undef_method, :hoobatz
uploader_class.singleton_class.send :undef_method, :hoobatz=
uploader_class.send :undef_method, :hoobatz
uploader_class.send :undef_method, :hoobatz=
end
context "when the proc accepts no arguments" do
let(:this_proc) { proc { "a return value" } }
......
......@@ -5,6 +5,7 @@ describe CarrierWave::Uploader do
Class.new(CarrierWave::Uploader::Base).tap do |uc|
uc.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'XXXX', # required
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment