Sha256: 52d00a3e94a0d963fb4f11ff68818aa7b45e8716b18f78516d8acf8fcfd75497

Contents?: true

Size: 1.01 KB

Versions: 11

Compression:

Stored size: 1.01 KB

Contents

require "aws-sdk"

module RailsConnector

class Blob

  def self.find(id, options)
    new(blob_class.find(id, options))
  end

  def self.config
    @config or raise "Blob storage has not been configured yet"
  end

  def self.configure(spec)
    @config = spec.symbolize_keys
  end

  def self.blob_class
    @blob_class ||= blob_class_from_config
  end

  # for testing purposes
  def self.reset_blob_class_cache # :nodoc:
    @blob_class = nil
  end

  def self.blob_class_from_config
    blob_class =
        case config[:type]
        when "s3"
          S3Blob
        when "couch"
          CouchBlob
        else
          raise "Unsupported blob storage type #{config[:type]}"
        end
    blob_class.configure(config)
    blob_class
  end

  attr_reader :instance

  def initialize(blob_instance)
    @instance = blob_instance
  end

  def id
    instance.id
  end

  def url
    instance.url
  end

  def content_type
    instance.content_type
  end

  def length
    instance.length
  end

end

end # module RailsConnector

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.beta.200.869.9609b39 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.856.8c0fec5 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.809.bdfa8c3 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.785.05d4af9 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.744.99f67fc lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.720.44fbabd lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.713.e5c3150 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.681.7c84f4a lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.663.ceecdee lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.650.7c93155 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.beta.200.621.4c8e1b0 lib/rails_connector/blob.rb