Module: ROM::DataProxy::ClassMethods

Included in:
ArrayDataset, EnumerableDataset
Defined in:
core/lib/rom/data_proxy.rb

Instance Method Summary collapse

Instance Method Details

#forward(*methods) ⇒ undefined

Forward provided methods to the underlaying data object

Examples:


class MyDataset
  include DataProxy

  forward(:find_all, :map)
end

Returns:

  • (undefined)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'core/lib/rom/data_proxy.rb', line 76

def forward(*methods)
  # FIXME: we should probably raise if one of the non-forwardable methods
  #       was provided
  (methods - NON_FORWARDABLE).each do |method_name|
    class_eval <<-RUBY, __FILE__, __LINE__ + 1
      def #{method_name}(*args, &block)
        response = data.public_send(#{method_name.inspect}, *args, &block)

        if response.equal?(data)
          self
        elsif response.is_a?(data.class)
          self.class.new(response)
        else
          response
        end
      end
    RUBY
  end
end