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.3.115.227021242 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.3.73.75172665 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.3.2.153416031 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.3.67.110847540 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.3.1.23895778 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.2.36.82613853 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.2.7.128454143 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.1.26.236500544 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.1 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.539.93842523 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.529.114081979 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.518.30999728 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.515.34928522 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.498.46559598 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.480.261594408 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.444.171626367 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.406.131718077 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.356.19698103 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.348.160665197 lib/rails_connector/blob.rb
infopark_cloud_connector-6.8.0.328.4a753fc lib/rails_connector/blob.rb