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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/carrierwave/uploader/configuration.rb', line 110 def add_config(name) class_eval " def self.\#{name}(value=nil)\n @\#{name} = value if value\n return @\#{name} if self.object_id == \#{self.object_id} || defined?(@\#{name})\n name = superclass.\#{name}\n return 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\n end\n\n def self.\#{name}=(value)\n @\#{name} = value\n end\n\n def \#{name}\n self.class.\#{name}\n end\n RUBY\nend\n", __FILE__, __LINE__ + 1 |
#configure {|_self| ... } ⇒ Object
130 131 132 |
# File 'lib/carrierwave/uploader/configuration.rb', line 130 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
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/carrierwave/uploader/configuration.rb', line 96 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 |