Sha256: c4c7c4c778e4c2621143bc40ce3bf2d9baf521e82ce213638b49854034d960b3

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'carrierwave/processor/backend/base'
module CarrierWave::Processor

  class BackendNotInitializedError < StandardError
    def initialize msg="set up backend first"
      super
    end
  end

  class BackendNotFound < StandardError
    def initialize name
      super("backend with name #{name.to_s.classify} not found")
    end
  end

  class Configuration
    delegate :callback, :errback, :stub, :stub_cache, :to => :backend

    attr_writer :backend

    def delay
      self
    end

    def backend name=nil, options={}
      if name
        backends_path = (::CarrierWave::Processor.root + 'carrierwave/processor/backend')
        backend_file = backends_path.entries.detect{|i| i.basename('.rb').to_s == name.to_s}
        raise BackendNotFound.new(name) unless backend_file
        backend_file = backends_path + backend_file
        require backend_file
        raise BackendNotFound.new(name) unless backend_file
        begin
          klass = ::CarrierWave::Processor::Backend.const_get(name.to_s.classify.to_sym)
        rescue NameError
          raise BackendNotFound.new(name)
        end
        options = @backend.options.merge(options) if @backend
        @backend = klass.new options
      elsif @backend
        @backend
      else
        raise BackendNotInitializedError.new
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
carrierwave-processor-1.1.0 lib/carrierwave/processor/configuration.rb