Module: ActiveFedora::Delegation

Extended by:
ActiveSupport::Concern
Included in:
Relation
Defined in:
lib/active_fedora/relation/delegation.rb

Overview

:nodoc:

Constant Summary collapse

BLACKLISTED_ARRAY_METHODS =

This module creates compiled delegation methods dynamically at runtime, which makes subsequent calls to that method faster by avoiding method_missing. The delegations may vary depending on the klass of a relation, so we create a subclass of Relation for each different klass, and the delegations are compiled into that subclass only.

[
  :compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!,
  :shuffle!, :slice!, :sort!, :sort_by!, :delete_if,
  :keep_if, :pop, :shift, :delete_at, :select!
].to_set

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (protected)



25
26
27
28
29
30
31
32
# File 'lib/active_fedora/relation/delegation.rb', line 25

def method_missing(method, *args, &block)
  if array_delegable?(method)
    self.class.delegate method, to: :to_a
    to_a.public_send(method, *args, &block)
  else
    super
  end
end