Sha256: 3ddd77d7dbb55559b9c9372896d4161b5fed51cad3ab5414c6bd453bad56a9a8

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

module Gyazo
  class Image
    attr_reader :file
    def initialize(upload_data)
      @file = upload_data[:tempfile]
    end

    def upload
      @url = self.adapter.upload
    end

    def url
      @url
    end

    def data
      @data ||= @file.read
    end

    def name
      @name ||= Digest::MD5.hexdigest(data).to_s + ".jpg"
    end

    protected
    def adapter
      @adapter ||= self.class.adapter_class.new(self)
    end

    class << self
      def adapter_class
        @adapter || ::Gyazo::UploadAdapters::Fog
      end

      def adapter=(sym_or_klass)
        if sym_or_klass.kind_of?(Symbol)
          @adapter = adapter_map[sym_or_klass]
        else
          @adapter = sym_or_klass
        end
      end

      protected
      def adapter_map
        {
          :fog => ::Gyazo::UploadAdapters::Fog
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rack_gyazo-0.1.2 lib/gyazo/image.rb
rack_gyazo-0.1.1 lib/gyazo/image.rb
rack_gyazo-0.1.0 lib/gyazo/image.rb