Module: CarrierWave::Uploader::Configuration::ClassMethods
- Defined in:
- lib/carrierwave/uploader/configuration.rb
Instance Method Summary collapse
- #add_config(name) ⇒ Object
- #configure {|_self| ... } ⇒ Object
-
#storage(storage = nil) ⇒ Object
(also: #storage=)
Sets the storage engine to be used when storing files with this uploader.
Instance Method Details
#add_config(name) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/carrierwave/uploader/configuration.rb', line 112 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}) name = superclass.#{name} return nil if name.nil? && !instance_variable_defined?("@#{name}") @#{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 end def self.#{name}=(value) @#{name} = value end def #{name} self.class.#{name} end RUBY end |
#configure {|_self| ... } ⇒ Object
132 133 134 |
# File 'lib/carrierwave/uploader/configuration.rb', line 132 def configure yield self 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
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/carrierwave/uploader/configuration.rb', line 98 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 end return @storage end |