Module: CarrierWave::Uploader::Configuration::ClassMethods

Defined in:
lib/carrierwave/uploader/configuration.rb

Instance Method Summary collapse

Instance Method Details

#add_config(name) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/carrierwave/uploader/configuration.rb', line 117

def add_config(name)
  class_eval "def self.eager_load_fog(fog_credentials)\n# see #1198. This will hopefully no longer be necessary after fog 2.0\nrequire self.fog_provider\nrequire 'carrierwave/storage/fog'\nFog::Storage.new(fog_credentials) if fog_credentials.present?\nend\n\ndef self.\#{name}(value=nil)\n@\#{name} = value if value\neager_load_fog(value) if value && '\#{name}' == 'fog_credentials'\nreturn @\#{name} if self.object_id == \#{self.object_id} || defined?(@\#{name})\nname = superclass.\#{name}\nreturn nil if name.nil? && !instance_variable_defined?(\"@\#{name}\")\n@\#{name} = name && !name.is_a?(Module) && !name.is_a?(Symbol) && !name.is_a?(Numeric) && !name.is_a?(TrueClass) && !name.is_a?(FalseClass) ? name.dup : name\nend\n\ndef self.\#{name}=(value)\neager_load_fog(value) if '\#{name}' == 'fog_credentials' && value.present?\n@\#{name} = value\nend\n\ndef \#{name}=(value)\nself.class.eager_load_fog(value) if '\#{name}' == 'fog_credentials' && value.present?\n@\#{name} = value\nend\n\ndef \#{name}\nvalue = @\#{name} if instance_variable_defined?(:@\#{name})\nvalue = self.class.\#{name} unless instance_variable_defined?(:@\#{name})\nif value.instance_of?(Proc)\nvalue.arity >= 1 ? value.call(self) : value.call\nelse\nvalue\nend\nend\n", __FILE__, __LINE__ + 1
end

#cache_storage(storage = nil) ⇒ Object Also known as: cache_storage=

Sets the cache storage engine to be used when storing cache files with this uploader. Same as .storage except for required methods being #cache!(CarrierWave::SanitizedFile), #retrieve_from_cache! and #delete_dir!.

Parameters

storage (Symbol, Class)

The cache storage engine to use for this uploader

Returns

Class

the cache storage engine to be used with this uploader

Examples

cache_storage :file
cache_storage CarrierWave::Storage::File
cache_storage MyCustomStorageEngine


109
110
111
112
113
114
# File 'lib/carrierwave/uploader/configuration.rb', line 109

def cache_storage(storage = nil)
  if storage
    self._cache_storage = storage.is_a?(Symbol) ? eval(storage_engines[storage]) : storage
  end
  _cache_storage
end

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



157
158
159
# File 'lib/carrierwave/uploader/configuration.rb', line 157

def configure
  yield self
end

#reset_configObject

sets configuration back to default



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/carrierwave/uploader/configuration.rb', line 164

def reset_config
  configure do |config|
    config.permissions = 0644
    config.directory_permissions = 0755
    config.storage_engines = {
      :file => "CarrierWave::Storage::File",
      :fog  => "CarrierWave::Storage::Fog"
    }
    config.storage = :file
    config.cache_storage = :file
    config.fog_provider = 'fog'
    config.fog_attributes = {}
    config.fog_credentials = {}
    config.fog_public = true
    config.fog_authenticated_url_expiration = 600
    config.fog_use_ssl_for_aws = true
    config.store_dir = 'uploads'
    config.cache_dir = 'uploads/tmp'
    config.delete_tmp_file_after_storage = true
    config.move_to_cache = false
    config.move_to_store = false
    config.remove_previously_stored_files_after_update = true
    config.ignore_integrity_errors = true
    config.ignore_processing_errors = true
    config.ignore_download_errors = true
    config.validate_integrity = true
    config.validate_processing = true
    config.validate_download = true
    config.root = lambda { CarrierWave.root }
    config.base_path = CarrierWave.base_path
    config.enable_processing = true
    config.ensure_multipart_form = true
  end
end

#storage(storage = nil) ⇒ Object Also known as: storage=

Sets the storage engine to be used when storing files with this uploader. Can be any class that implements a #store!(CarrierWave::SanitizedFile) and a #retrieve! method. See lib/carrierwave/storage/file.rb for an example. Storage engines should be added to CarrierWave::Uploader::Base.storage_engines so they can be referred to by a symbol, which should be more convenient

If no argument is given, it will simply return the currently used storage engine.

Parameters

storage (Symbol, Class)

The storage engine to use for this uploader

Returns

Class

the storage engine to be used with this uploader

Examples

storage :file
storage CarrierWave::Storage::File
storage MyCustomStorageEngine


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/carrierwave/uploader/configuration.rb', line 73

def storage(storage = nil)
  case storage
  when Symbol
    if storage_engine = storage_engines[storage]
      self._storage = eval storage_engine
    else
      raise CarrierWave::UnknownStorageError, "Unknown storage: #{storage}"
    end
  when nil
    storage
  else
    self._storage = storage
  end
  _storage
end