Sha256: fe2e62267deacea523482dbe4da759c9648d84e4a8f9469ddbe6b91e16dbe5f4

Contents?: true

Size: 748 Bytes

Versions: 248

Compression:

Stored size: 748 Bytes

Contents

class Chef
  module ChefFS
    class Parallelizer
      class FlattenEnumerable
        include Enumerable

        def initialize(enum, levels = nil)
          @enum = enum
          @levels = levels
        end

        attr_reader :enum
        attr_reader :levels

        def each(&block)
          enum.each do |value|
            flatten(value, levels, &block)
          end
        end

        private

        def flatten(value, levels, &block)
          if levels != 0 && value.respond_to?(:each) && !value.is_a?(String)
            value.each do |child|
              flatten(child, levels.nil? ? levels : levels - 1, &block)
            end
          else
            yield(value)
          end
        end
      end
    end
  end
end

Version data entries

248 entries across 248 versions & 1 rubygems

Version Path
chef-12.11.18-universal-mingw32 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.11.18 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.10.24 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.10.24-universal-mingw32 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.9.41 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.9.41-universal-mingw32 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.9.38 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb
chef-12.9.38-universal-mingw32 lib/chef/chef_fs/parallelizer/flatten_enumerable.rb