Sha256: 98edb5d29ad8baf363090625f3544324734405ad311512e8daea61d27b706f19

Contents?: true

Size: 515 Bytes

Versions: 18

Compression:

Stored size: 515 Bytes

Contents

module Elastic::Support
  module Traversable
    def traverse(&_block)
      raise NotImplementedError, "every traversable tree must implement 'traverse'"
    end

    def pick(*_types, &_block)
      if _types.empty?
        enum = Enumerator.new do |y|
          traverse { |h| y << h }
        end
      else
        enum = Enumerator.new do |y|
          traverse { |h| y << h if _types.any? { |t| h.is_a? t } }
        end
      end

      return enum if _block.nil?
      enum.each(&_block)
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
elastic-rails-1.0.2 lib/elastic/support/traversable.rb
elastic-rails-1.0.1 lib/elastic/support/traversable.rb
elastic-rails-1.0.0 lib/elastic/support/traversable.rb
elastic-rails-0.8.7 lib/elastic/support/traversable.rb
elastic-rails-0.8.6 lib/elastic/support/traversable.rb
elastic-rails-0.8.5 lib/elastic/support/traversable.rb
elastic-rails-0.8.4 lib/elastic/support/traversable.rb
elastic-rails-0.8.3 lib/elastic/support/traversable.rb
elastic-rails-0.8.2 lib/elastic/support/traversable.rb
elastic-rails-0.8.1 lib/elastic/support/traversable.rb
elastic-rails-0.8.0 lib/elastic/support/traversable.rb
elastic-rails-0.7.0 lib/elastic/support/traversable.rb
elastic-rails-0.6.4 lib/elastic/support/traversable.rb
elastic-rails-0.6.3 lib/elastic/support/traversable.rb
elastic-rails-0.6.2 lib/elastic/support/traversable.rb
elastic-rails-0.6.1 lib/elastic/support/traversable.rb
elastic-rails-0.6.0 lib/elastic/support/traversable.rb
elastic-rails-0.5.0 lib/elastic/support/traversable.rb