Sha256: 60a3f69d90784806570c7bc4041e6dec4eec4ebe1f3b721645ace3b8b36f16f0

Contents?: true

Size: 1.18 KB

Versions: 21

Compression:

Stored size: 1.18 KB

Contents

require "aws-sdk"

module RailsConnector

class Blob

  class << self
    def find(id)
      new(blob_class.find(id))
    end

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

    def configure(spec)
      @config = spec.symbolize_keys
      @blob_class = nil
    end

    def blob_class
      @blob_class ||= blob_class_from_config
    end

    # for testing purposes
    def reset_blob_class_cache
      @blob_class = nil
    end

    def unconfigure
      @config = nil
    end

    private

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

  def initialize(blob_instance)
    @instance = blob_instance
  end

  def id
    instance.id
  end

  def url
    instance.url
  end

  def meta_url
    instance.meta_url
  end

  def content_type
    instance.content_type
  end

  def length
    instance.length
  end

  private

  attr_reader :instance

end

end # module RailsConnector

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
infopark_cloud_connector-6.8.0.322.c003f11 lib/rails_connector/blob.rb