Class: Timeful::RelationProxy

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/timeful/relation_proxy.rb

Overview

Makes Array behave much like ActiveRecord::Relation.

This proxy class wraps an Array or ActiveRecord::Relation instance and makes the former behave like the latter by simulating methods like find_each.

Author:

  • Alessandro Desantis

Instance Method Summary collapse

Instance Method Details

#find_each(*args) {|item| ... } ⇒ Object

If find_each is defined on the object we’re delegating to (i.e. the object is an instance of ActiveRecord::Relation), calls it on the object.

Otherwise, calls each on the object and yields the values.

Yield Parameters:

  • item (Object)

    the items in the object



16
17
18
19
20
21
22
23
24
# File 'lib/timeful/relation_proxy.rb', line 16

def find_each(*args, &block)
  method = if __getobj__.respond_to?(:find_each)
    :find_each
  else
    :each
  end

  __getobj__.send(method, *args, &block)
end