Sha256: c7d469209fe96480bdcf492da656563f113f2f6ac9d2ca4c4a4e63fcd839869c

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'rom/initializer'
require 'rom/enumerable_dataset'

module ROM
  # A helper module that adds data-proxy behavior to an array-like object
  #
  # @see EnumerableDataset
  #
  # @api public
  module ArrayDataset
    extend DataProxy::ClassMethods
    include EnumerableDataset

    # Extends the class with data-proxy behavior
    #
    # @api private
    def self.included(klass)
      klass.class_eval do
        extend Initializer
        include DataProxy

        param :data
      end
    end

    forward(
      :*, :+, :-, :compact, :compact!, :flatten, :flatten!, :length, :pop,
      :reverse, :reverse!, :sample, :size, :shift, :shuffle, :shuffle!,
      :slice, :slice!, :sort!, :uniq, :uniq!, :unshift, :values_at
    )

    %i[
      map! combination cycle delete_if keep_if permutation reject!
      select! sort_by!
    ].each do |method|
      class_eval <<-RUBY, __FILE__, __LINE__ + 1
        def #{method}(*args, &block)
          return to_enum unless block
          self.class.new(data.send(:#{method}, *args, &block), **options)
        end
      RUBY
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/array_dataset.rb
rom-core-5.3.1 lib/rom/array_dataset.rb
rom-core-5.3.0 lib/rom/array_dataset.rb
rom-core-5.2.6 lib/rom/array_dataset.rb
rom-core-5.2.5 lib/rom/array_dataset.rb
rom-core-5.2.4 lib/rom/array_dataset.rb
rom-core-5.2.3 lib/rom/array_dataset.rb
rom-core-5.2.2 lib/rom/array_dataset.rb
rom-core-5.2.1 lib/rom/array_dataset.rb