Sha256: 2e073c6d866407e92cd4dd7eaad08e5a7511935fb8f850a8dfaa833ef3afa610

Contents?: true

Size: 1.57 KB

Versions: 13

Compression:

Stored size: 1.57 KB

Contents

require 'attached/storage/base'

module Attached
	module Storage
		class Local < Base
			
			
			attr_reader :mode
			
			
			# Create a new interface supporting save and destroy operations.
			#
			# Usage:
			#
			#		Attached::Storage::Local.new()
			
			def initialize()
				@mode = 0644
			end
			
			
			# Access the host (e.g. /system/) for a storage service.
			#
			# Usage:
			#
			#		storage.host
			
			def host()
			  "/system/"
			end
			
			
      # Save a file to a given path.
      #
      # Parameters:
      #
      # * file - The file to save.
      # * path - The path to save.
      
      def save(file, path)
        path = "#{Rails.root}/public/system/#{path}"
        dirname, basename = File.split(path)
        
        return if file.path == path
        
        begin
          FileUtils.mkdir_p(dirname)
          FileUtils.cp(file.path, path)
          FileUtils.chmod(self.mode, path)
        rescue Errno::ENOENT
        end
      end
      
      
      # Retrieve a file from a given path.
      #
      # Parameters:
      #
      # * path - The path to retrieve.
      
      def retrieve(path)
        path = "#{Rails.root}/public/system/#{path}"
        
        File.open(path)
      end
      
      
      # Destroy a file at a given path.
      #
      # Parameters:
      #
      # * path - The path to destroy.
      
      def destroy(path)
        path = "#{Rails.root}/public/system/#{path}"
        dirname, basename = File.split(path)
    
        begin
          FileUtils.rm(path)
        rescue Errno::ENOENT
        end
      end
      
			
		end
	end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
attached-0.5.2 lib/attached/storage/local.rb
attached-0.5.1 lib/attached/storage/local.rb
attached-0.5.0 lib/attached/storage/local.rb
attached-0.4.9 lib/attached/storage/local.rb
attached-0.4.8 lib/attached/storage/local.rb
attached-0.4.7 lib/attached/storage/local.rb
attached-0.4.6 lib/attached/storage/local.rb
attached-0.4.5 lib/attached/storage/local.rb
attached-0.4.4 lib/attached/storage/local.rb
attached-0.4.3 lib/attached/storage/local.rb
attached-0.4.2 lib/attached/storage/local.rb
attached-0.4.1 lib/attached/storage/local.rb
attached-0.4.0 lib/attached/storage/local.rb