Module: ROM::DataProxy

Defined in:
core/lib/rom/data_proxy.rb

Overview

Helper module for dataset classes

It provides a constructor accepting data, header and an optional row_proc. This module is used internally by EnumerableDataset and ArrayDataset.

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

NON_FORWARDABLE =
%i[
  each to_a to_ary kind_of? instance_of? is_a?
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wrapped data array

Returns:

  • (Object)

    Data object for the iterator



20
21
22
# File 'core/lib/rom/data_proxy.rb', line 20

def data
  @data
end

#row_procProc (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns tuple processing proc.

Returns:

  • (Proc)

    tuple processing proc



25
26
27
# File 'core/lib/rom/data_proxy.rb', line 25

def row_proc
  @row_proc
end

Class Method Details

.included(klass) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Extends the class with forward DSL and Equalizer using data attribute



32
33
34
35
36
37
38
39
40
# File 'core/lib/rom/data_proxy.rb', line 32

def self.included(klass)
  klass.class_eval do
    extend ClassMethods

    include Dry::Equalizer(:data)

    option :row_proc, default: -> { self.class.row_proc }
  end
end

Instance Method Details

#eachEnumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterate over data using row_proc

Returns:

  • (Enumerator)

    if block is not given



47
48
49
50
51
# File 'core/lib/rom/data_proxy.rb', line 47

def each
  return to_enum unless block_given?

  data.each { |tuple| yield(row_proc[tuple]) }
end