method
match
Ruby on Rails latest stable (v7.1.3.2)
-
0 notes -
Class: ActiveRecord::DynamicFinderMatch
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2
- 4.1.8
- 4.2.1
- 4.2.7
- 4.2.9
- 5.0.0.1
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
match(method)
public
Hide source
# File activerecord/lib/active_record/dynamic_finder_match.rb, line 8 def self.match(method) finder = :first bang = false instantiator = nil case method.to_s when /^find_(all_|last_)?by_([_a-zA-Z]\w*)$/ finder = :last if $1 == 'last_' finder = :all if $1 == 'all_' names = $2 when /^find_by_([_a-zA-Z]\w*)\!$/ bang = true names = $1 when /^find_or_create_by_([_a-zA-Z]\w*)\!$/ bang = true instantiator = :create names = $1 when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/ instantiator = $1 == 'initialize' ? :new : :create names = $2 else return nil end new(finder, instantiator, bang, names.split('_and_')) end