Sha256: ab88343be9fcee2fccfff7760071c5290266a0f8742c614eee297d855cd9551e

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require 'fog/core/model'
require 'fog/aliyun/models/storage/files'

module Fog
  module Aliyun
    class Storage
      class Directory < Fog::Model
        identity :key, :aliases => ['Key', 'Name', 'name']

        def destroy
          requires :key
          prefix = key + '/'
          ret = service.list_objects(prefix: prefix)['Contents']

          if ret.nil?
            false
          elsif ret.size == 1
            service.delete_container(key)
            true
          else
            raise Fog::Aliyun::Storage::Error, ' Forbidden: Direction not empty!'
            false
          end
        end

        def files
          @files ||= begin
            Fog::Aliyun::Storage::Files.new(
              directory: self,
              service: service
            )
          end
        end

        def public_url
          nil
        end

        def save
          requires :key

          # Checking whether the key is a bucket and meet the multi-bucket scenario.
          # If the key is a existing bucket, return it directly.
          key = key.chomp('/')
          if !key.nil? && key != '' && key != '.' && !(key.include? '/')
            data = service.get_bucket(key)
            if data.class == Hash && data.key?('Code') && !data['Code'].nil? && !data['Code'].empty?
              service.put_container(key)
            end
          end

          true
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fog-aliyun-0.3.18 lib/fog/aliyun/models/storage/directory.rb
fog-aliyun-0.3.17 lib/fog/aliyun/models/storage/directory.rb
fog-aliyun-0.3.16 lib/fog/aliyun/models/storage/directory.rb
fog-aliyun-0.3.15 lib/fog/aliyun/models/storage/directory.rb
fog-aliyun-0.3.13 lib/fog/aliyun/models/storage/directory.rb
fog-aliyun-0.3.12 lib/fog/aliyun/models/storage/directory.rb
fog-aliyun-0.3.11 lib/fog/aliyun/models/storage/directory.rb