Sha256: 86b964783f5286080fb00a43f6b19b2acf2b4b2b739df29ca020a93ac5358f61

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 KB

Contents

module Balloon
  class Base
    include Balloon::Uploader

    def self.uploader(name)
      class_eval <<-RUBY
        def initialize(upload_file = nil)
          set_storage_engine
          @file = upload_file.is_a?(Hash) ? upload_file[:#{name}] : upload_file 
        end

        def #{name}
          @meta
        end

        def uploader_name
          "#{name}".pluralize
        end

        def set_storage_engine
          return if respond_to?(:@storage_engine)
          @storage_engine = eval(STORAGE_EGINE[store_storage.to_sym]).new(self) 
        end
      RUBY
    end

    # upload file save storage
    #
    # @param [File] upload_file the upload file
    #
    def upload_store(upload_file = nil)
      uploader_file = upload_file.nil? ? @file : upload_file
      save_to_cache(uploader_file)
      store_info = storage_engine.store!
      @meta[:filename] = store_info[:filename]
      @meta[:basename] = store_info[:basename]
    end
    
    def from_store(size_name = nil)
      storage_engine.retrieve!(size_name)
    end

    def path(size_name = nil)
      storage_engine.path!(size_name)
    end

    def local_path(size_name = nil)
      storage_engine.local_path!(size_name)
    end

    def upload_delete
      storage_engine.delete!
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
balloon-1.1.7 lib/balloon/base.rb
balloon-1.1.6 lib/balloon/base.rb
balloon-1.1.5 lib/balloon/base.rb
balloon-1.1.4 lib/balloon/base.rb
balloon-1.1.3 lib/balloon/base.rb