Sha256: 4d059aca9e33bfef47506f37f59bc784ccde4bb8cac0984211f226ff790ef236

Contents?: true

Size: 1.71 KB

Versions: 40

Compression:

Stored size: 1.71 KB

Contents

module Fog
  module CDN
    class AWS
      class Invalidation < Fog::Model
        identity :id,                :aliases => 'Id'

        attribute :status,           :aliases => 'Status'
        attribute :create_time,      :aliases => 'CreateTime'
        attribute :caller_reference, :aliases => 'CallerReference'
        attribute :paths,            :aliases => 'Paths'

        def initialize(new_attributes={})
          new_attributes[:caller_reference] ||= Time.now.utc.to_i.to_s
          super(invalidation_to_attributes(new_attributes))
        end

        def distribution
          @distribution
        end

        def ready?
          requires :id, :status
          status == 'Completed'
        end

        def save
          requires :paths, :caller_reference
          raise "Submitted invalidation cannot be submitted again" if persisted?
          response = service.post_invalidation(distribution.identity, paths, caller_reference)
          merge_attributes(invalidation_to_attributes(response.body))
          true
        end

        def destroy
          # invalidations can't be removed, but tests are requiring they do :)
          true
        end

        private

        def distribution=(dist)
          @distribution = dist
        end

        def invalidation_to_attributes(new_attributes={})
          invalidation_batch = new_attributes.delete('InvalidationBatch') || {}
          if invalidation_batch['Path']
            new_attributes[:paths] = invalidation_batch['Path']
          end
          if invalidation_batch['CallerReference']
            new_attributes[:caller_reference] = invalidation_batch['CallerReference']
          end
          new_attributes
        end
      end
    end
  end
end

Version data entries

40 entries across 38 versions & 3 rubygems

Version Path
fog-aws-3.2.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-3.1.0 lib/fog/aws/models/cdn/invalidation.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-aws-2.0.1/lib/fog/aws/models/cdn/invalidation.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-aws-2.0.1/lib/fog/aws/models/cdn/invalidation.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-aws-2.0.1/lib/fog/aws/models/cdn/invalidation.rb
fog-aws-3.0.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-2.0.1 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-2.0.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.4.1 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.4.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.3.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.2.1 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.2.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.1.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-1.0.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-0.13.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-0.12.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-0.11.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-0.10.0 lib/fog/aws/models/cdn/invalidation.rb
fog-aws-0.9.4 lib/fog/aws/models/cdn/invalidation.rb