Module: Enrich::AutoDelegate

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/enrich/auto_delegate.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Delegates missing instance methods to the source object.



8
9
10
11
12
13
# File 'lib/enrich/auto_delegate.rb', line 8

def method_missing(method, *args, &block)
  return super unless delegatable?(method)

  # self.singleton_class.delegate method, to: :object
  object.send(method, *args, &block)
end

Instance Method Details

#delegatable?(method) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/enrich/auto_delegate.rb', line 21

def delegatable?(method)
  object.respond_to?(method)
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Checks if the decorator responds to an instance method, or is able to proxy it to the source object.

Returns:

  • (Boolean)


17
18
19
# File 'lib/enrich/auto_delegate.rb', line 17

def respond_to_missing?(method, include_private = false)
  super || delegatable?(method)
end