Sha256: 7e078109435b5e56d1d20a137773585d2660f2c03adc956fe2361006a9455d6f

Contents?: true

Size: 2 KB

Versions: 1

Compression:

Stored size: 2 KB

Contents

require 'fog/core/model'

module Fog
  module Storage
    class Artifactory
      class File < Fog::Model
        identity :key, aliases: 'path'

        attribute :checksums
        attribute :original_checksums, aliases: 'originalChecksums'
        attribute :created, type: :time
        attribute :created_by, aliases: 'createdBy'
        attribute :download_uri, aliases: 'downloadUri'
        attribute :last_modified, aliases: 'lastModified', type: :time
        attribute :last_updated, aliases: 'lastUpdated', type: :time
        attribute :content_type, aliases: %w(mimeType mime_type)
        attribute :modified_by, aliases: 'modifiedBy'
        attribute :repo
        attribute :content_length, aliases: 'size', type: :integer
        attribute :uri

        def body
          return attributes[:body] if attributes[:body]
          return '' unless last_modified
          attributes[:body] = service.client.get(download_uri)
        end

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

        def directory
          @directory
        end

        def destroy
          requires :directory, :key
          service.client.delete(attributes[:download_uri])
          true
        end

        def save(_options = {})
          requires :body, :directory, :key
          endpoint = ::File.join(attributes[:directory].key, attributes[:key])

          service.client.put(endpoint, attributes[:body])
          true
        end

        def public_url
          requires :directory, :key
          self.download_uri
        end
        alias_method :url, :public_url

        def download_uri
          return attributes[:download_uri] if attributes[:download_uri].present?
          requires :directory, :key
          ::File.join(service.client.endpoint, attributes[:directory].key, attributes[:key])
        end

        #   puts attributes[:directory].key
        #   URI.join(service.client.endpoint, attributes[:directory].key, attributes[:key]).to_s
        # end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fog-artifactory-0.2.0 lib/fog/artifactory/models/storage/file.rb