Sha256: adfccaea8ca273d6730303e8fbdf109325f8651e1ce867f722e7aff628d99769

Contents?: true

Size: 1.51 KB

Versions: 16

Compression:

Stored size: 1.51 KB

Contents

require 'fog/core/model'

module Fog
  module Local
    class Storage

      class File < Fog::Model

        identity  :key,             :aliases => 'Key'

        attribute :content_length,  :aliases => 'Content-Length'
        # attribute :content_type,    :aliases => 'Content-Type'
        attribute :last_modified,   :aliases => 'Last-Modified'

        def body
          attributes[:body] ||= if last_modified
            collection.get(identity).body
          else
            ''
          end
        end

        def body=(new_body)
          attributes[:body] = new_body
        end

        def directory
          @directory
        end

        def destroy
          requires :directory, :key
          ::File.delete(path)
          true
        end

        def public=(new_public)
          new_public
        end

        def public_url
          nil
        end

        def save(options = {})
          requires :body, :directory, :key
          file = ::File.new(path, 'w')
          if body.is_a?(String)
            file.write(body)
          else
            file.write(body.read)
          end
          file.close
          merge_attributes(
            :content_length => ::File.size(path),
            :last_modified  => ::File.mtime(path)
          )
          true
        end

        private

        def directory=(new_directory)
          @directory = new_directory
        end

        def path
          connection.path_to(::File.join(directory.key, CGI.escape(key)))
        end

      end

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
phpfog-fog-0.4.1.3 lib/fog/storage/models/local/file.rb
phpfog-fog-0.4.1.2 lib/fog/storage/models/local/file.rb
phpfog-fog-0.4.1.1 lib/fog/storage/models/local/file.rb
phpfog-fog-0.4.1 lib/fog/storage/models/local/file.rb
fog-0.4.1 lib/fog/storage/models/local/file.rb
fog-0.4.0 lib/fog/local/models/storage/file.rb
fog-0.3.34 lib/fog/local/models/storage/file.rb
fog-0.3.33 lib/fog/local/models/storage/file.rb
fog-0.3.32 lib/fog/local/models/storage/file.rb
fog-0.3.31 lib/fog/local/models/storage/file.rb
fog-0.3.30 lib/fog/local/models/storage/file.rb
fog-0.3.29 lib/fog/local/models/storage/file.rb
fog-0.3.28 lib/fog/local/models/storage/file.rb
fog-0.3.27 lib/fog/local/models/storage/file.rb
fog-0.3.26 lib/fog/local/models/storage/file.rb
fog-0.3.25 lib/fog/local/models/storage/file.rb