Module: ROM::DataProxy

Defined in:
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 =
[
  :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



18
19
20
# File 'lib/rom/data_proxy.rb', line 18

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



23
24
25
# File 'lib/rom/data_proxy.rb', line 23

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



30
31
32
33
34
35
36
37
38
# File 'lib/rom/data_proxy.rb', line 30

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



45
46
47
48
# File 'lib/rom/data_proxy.rb', line 45

def each
  return to_enum unless block_given?
  data.each { |tuple| yield(row_proc[tuple]) }
end