Sha256: eacb431b816fc37991d1c06bc6e2799270ceb3eff4e62decd41b5a28c2d2cd98

Contents?: true

Size: 1.07 KB

Versions: 54

Compression:

Stored size: 1.07 KB

Contents

require 'fog/model'

module Fog
  module Local

    class File < Fog::Model

      identity  :key,             'Key'

      attr_accessor :body
      attribute :content_length,  'Content-Length'
      # attribute :content_type,    'Content-Type'
      attribute :last_modified,   'Last-Modified'

      def body
        @body ||= if last_modified
          collection.get(identity).body
        else
          ''
        end
      end

      def directory
        @directory
      end

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

      def save(options = {})
        requires :body, :directory, :key
        file = ::File.new(path, 'w')
        file.write(body)
        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, key))
      end

    end

  end
end

Version data entries

54 entries across 54 versions & 2 rubygems

Version Path
fog-0.2.30 lib/fog/local/models/file.rb
fog-0.2.28 lib/fog/local/models/file.rb
fog-0.2.27 lib/fog/local/models/file.rb
fog-0.2.26 lib/fog/local/models/file.rb
fog-0.2.25 lib/fog/local/models/file.rb
fog-0.2.24 lib/fog/local/models/file.rb
tecnh-fog-0.2.23.vpc lib/fog/local/models/file.rb
fog-0.2.23 lib/fog/local/models/file.rb
fog-0.2.22 lib/fog/local/models/file.rb
fog-0.2.21 lib/fog/local/models/file.rb
fog-0.2.20 lib/fog/local/models/file.rb
fog-0.2.19 lib/fog/local/models/file.rb
fog-0.2.18 lib/fog/local/models/file.rb
fog-0.2.17 lib/fog/local/models/file.rb
fog-0.2.16 lib/fog/local/models/file.rb
fog-0.2.15 lib/fog/local/models/file.rb
fog-0.2.14 lib/fog/local/models/file.rb
fog-0.2.13 lib/fog/local/models/file.rb
fog-0.2.12 lib/fog/local/models/file.rb
fog-0.2.11 lib/fog/local/models/file.rb