Sha256: 1919ff477831ac0715e376e23ead489b492cc99a3a0cee1b7369276c3e65996e

Contents?: true

Size: 1.26 KB

Versions: 62

Compression:

Stored size: 1.26 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(options={})
          limit = options[:limit] || 100

          if !block_given?
            self
          else
            subset = dup.all

            subset.each_entry { |f| yield f }

            while subset.truncated
              subset.
                all(:marker => subset.marker, :limit => limit).
                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

62 entries across 60 versions & 2 rubygems

Version Path
fog-aws-3.30.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.29.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.28.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.27.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.26.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.25.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.24.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.23.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.22.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.21.1 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.21.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.20.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.19.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.18.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.17.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.16.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.15.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.14.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.13.0 lib/fog/aws/iam/paged_collection.rb
fog-aws-3.12.0 lib/fog/aws/iam/paged_collection.rb