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

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

Instance Method Summary collapse

Instance Method Details

#add_config(name) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/carrierwave/uploader/configuration.rb', line 94

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

Yields:

  • (_self)

Yield Parameters:



114
115
116
# File 'lib/carrierwave/uploader/configuration.rb', line 114

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


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/carrierwave/uploader/configuration.rb', line 80

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