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