Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1092c181b5
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (35 sloc) 0.931 kb
module ActiveRecord
class DynamicFinderMatch
def self.match(method)
df_match = self.new(method)
df_match.finder ? df_match : nil
end
def initialize(method)
@finder = :find_initial
case method.to_s
when /^find_(all_by|by)_([_a-zA-Z]\w*)$/
@finder = :find_every if $1 == 'all_by'
names = $2
when /^find_by_([_a-zA-Z]\w*)\!$/
@bang = true
names = $1
when /^find_or_(initialize|create)_by_([_a-zA-Z]\w*)$/
@instantiator = $1 == 'initialize' ? :new : :create
names = $2
else
@finder = nil
end
@attribute_names = names && names.split('_and_')
end
attr_reader :finder, :attribute_names, :instantiator
def finder?
!@finder.nil? && @instantiator.nil?
end
def instantiator?
@finder == :find_initial && !@instantiator.nil?
end
def bang?
@bang
end
end
end
Jump to Line
Something went wrong with that request. Please try again.