lib/carrierwave/uploader/configuration.rb in locomotive_carrierwave-0.5.0.1 vs lib/carrierwave/uploader/configuration.rb in locomotive_carrierwave-0.5.4.beta1
- old
+ new
@@ -3,23 +3,30 @@
module Uploader
module Configuration
extend ActiveSupport::Concern
included do
+ class_inheritable_accessor :_storage, :instance_reader => false, :instance_writer => false
+
add_config :root
add_config :permissions
add_config :storage_engines
add_config :s3_access_policy
add_config :s3_bucket
add_config :s3_access_key_id
add_config :s3_secret_access_key
add_config :s3_cnamed
add_config :s3_headers
+ add_config :s3_region
+ add_config :s3_use_ssl
+ add_config :s3_authentication_timeout
add_config :cloud_files_username
add_config :cloud_files_api_key
add_config :cloud_files_container
add_config :cloud_files_cdn_host
+ add_config :cloud_files_auth_url
+ add_config :cloud_files_snet
add_config :grid_fs_connection
add_config :grid_fs_database
add_config :grid_fs_host
add_config :grid_fs_port
add_config :grid_fs_username
@@ -27,43 +34,30 @@
add_config :grid_fs_access_url
add_config :store_dir
add_config :cache_dir
add_config :enable_processing
add_config :ensure_multipart_form
+ add_config :delete_tmp_file_after_storage
+ add_config :remove_previously_stored_files_after_update
+ # fog
+ add_config :fog_attributes
+ add_config :fog_credentials
+ add_config :fog_directory
+ add_config :fog_host
+ add_config :fog_public
+ add_config :fog_authenticated_url_expiration
+
# Mounting
add_config :ignore_integrity_errors
add_config :ignore_processing_errors
add_config :validate_integrity
add_config :validate_processing
add_config :mount_on
- configure do |config|
- config.permissions = 0644
- config.storage_engines = {
- :file => "CarrierWave::Storage::File",
- :s3 => "CarrierWave::Storage::S3",
- :grid_fs => "CarrierWave::Storage::GridFS",
- :right_s3 => "CarrierWave::Storage::RightS3",
- :cloud_files => "CarrierWave::Storage::CloudFiles"
- }
- config.storage = :file
- config.s3_headers = {}
- config.s3_access_policy = :public_read
- config.grid_fs_database = 'carrierwave'
- config.grid_fs_host = 'localhost'
- config.grid_fs_port = 27017
- config.store_dir = 'uploads'
- config.cache_dir = 'uploads/tmp'
- config.ignore_integrity_errors = true
- config.ignore_processing_errors = true
- config.validate_integrity = true
- config.validate_processing = true
- config.root = CarrierWave.root
- config.enable_processing = true
- config.ensure_multipart_form = true
- end
+ # set default values
+ reset_config
end
module ClassMethods
##
@@ -88,23 +82,17 @@
# storage :file
# storage CarrierWave::Storage::File
# storage MyCustomStorageEngine
#
def storage(storage = nil)
- if storage.is_a?(Symbol)
- @storage = eval(storage_engines[storage])
- elsif storage
- @storage = storage
- elsif @storage.nil?
- # Get the storage from the superclass if there is one
- @storage = superclass.storage rescue nil
+ if storage
+ self._storage = storage.is_a?(Symbol) ? eval(storage_engines[storage]) : storage
end
- return @storage
+ _storage
end
alias_method :storage=, :storage
-
def add_config(name)
class_eval <<-RUBY, __FILE__, __LINE__ + 1
def self.#{name}(value=nil)
@#{name} = value if value
return @#{name} if self.object_id == #{self.object_id} || defined?(@#{name})
@@ -123,9 +111,49 @@
RUBY
end
def configure
yield self
+ end
+
+ ##
+ # sets configuration back to default
+ #
+ def reset_config
+ configure do |config|
+ config.permissions = 0644
+ config.storage_engines = {
+ :file => "CarrierWave::Storage::File",
+ :fog => "CarrierWave::Storage::Fog",
+ :s3 => "CarrierWave::Storage::S3",
+ :grid_fs => "CarrierWave::Storage::GridFS",
+ :right_s3 => "CarrierWave::Storage::RightS3",
+ :cloud_files => "CarrierWave::Storage::CloudFiles"
+ }
+ config.storage = :file
+ config.s3_headers = {}
+ config.s3_access_policy = :public_read
+ config.s3_region = 'us-east-1'
+ config.s3_authentication_timeout = 600
+ config.grid_fs_database = 'carrierwave'
+ config.grid_fs_host = 'localhost'
+ config.grid_fs_port = 27017
+ config.fog_attributes = {}
+ config.fog_credentials = {}
+ config.fog_public = true
+ config.fog_authenticated_url_expiration = 600
+ config.store_dir = 'uploads'
+ config.cache_dir = 'uploads/tmp'
+ config.delete_tmp_file_after_storage = true
+ config.remove_previously_stored_files_after_update = true
+ config.ignore_integrity_errors = true
+ config.ignore_processing_errors = true
+ config.validate_integrity = true
+ config.validate_processing = true
+ config.root = CarrierWave.root
+ config.enable_processing = true
+ config.ensure_multipart_form = true
+ end
end
end
end
end