Sha256: 70bc3d1d8b129794ca1f7a9a192bd44a9e0bb754c245713f843d9d3bbec4592f

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

module Fog
  module AWS
    class IAM
      class PagedCollection < Fog::Collection
        def self.inherited(klass)
          klass.send(:attribute, :truncated, :aliases => 'IsTruncated', :type => :boolean)
          klass.send(:attribute, :marker,    :aliases => 'Marker')

          super
        end

        def each_entry(*args, &block)
          to_a.each(*args, &block)
        end

        def each
          if !block_given?
            self
          else
            subset = dup.all

            subset.each_entry { |f| yield f }

            while subset.truncated
              subset.
                all(:marker => subset.marker, :limit => 1000).
                each_entry { |f| yield f }
            end

            self
          end
        end

        protected

        def page_params(options={})
          marker = options.fetch(:marker) { options.fetch('Marker') { self.marker } }
          limit  = options.fetch(:limit) { options['MaxItems'] }
          params = {}

          if marker && !marker.empty?
            params.merge!('Marker' => marker)
          end

          if limit
            params.merge!('MaxItems' => limit)
          end

          params
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-aws-0.7.5/lib/fog/aws/iam/paged_collection.rb
fog-aws-0.7.6 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.7.5 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.7.4 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.7.3 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.7.2 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.6.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.5.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-0.4.1 lib/fog/aws/iam/paged_collection.rb