Module: ActiveRecord::DynamicMatchers

Included in:
Base
Defined in:
activerecord/lib/active_record/dynamic_matchers.rb

Overview

:nodoc:

Defined Under Namespace

Modules: Finder Classes: FindBy, FindByBang, Method

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object (private)



19
20
21
22
23
24
25
26
27
28
# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 19

def method_missing(name, *arguments, &block)
  match = Method.match(self, name)

  if match && match.valid?
    match.define
    send(name, *arguments, &block)
  else
    super
  end
end

Instance Method Details

#respond_to?(name, include_private = false) ⇒ Boolean

This code in this file seems to have a lot of indirection, but the indirection is there to provide extension points for the activerecord-deprecated_finders gem. When we stop supporting activerecord-deprecated_finders (from Rails 5), then we can remove the indirection.

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
# File 'activerecord/lib/active_record/dynamic_matchers.rb', line 8

def respond_to?(name, include_private = false)
  if self == Base
    super
  else
    match = Method.match(self, name)
    match && match.valid? || super
  end
end