756e6d2ad8
* This will significantly decrease the size of the msf install (~5 MB) * ActiveRecord & ActiveSupport are still used, and have been moved to lib/ git-svn-id: file:///home/svn/framework3/trunk@10682 4d416f70-5f16-0410-b530-b9f4589650da
42 lines
961 B
Ruby
42 lines
961 B
Ruby
module ActiveRecord
|
|
class DynamicFinderMatch
|
|
def self.match(method)
|
|
df_match = self.new(method)
|
|
df_match.finder ? df_match : nil
|
|
end
|
|
|
|
def initialize(method)
|
|
@finder = :first
|
|
case method.to_s
|
|
when /^find_(all_by|last_by|by)_([_a-zA-Z]\w*)$/
|
|
@finder = :last if $1 == 'last_by'
|
|
@finder = :all 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 == :first && !@instantiator.nil?
|
|
end
|
|
|
|
def bang?
|
|
@bang
|
|
end
|
|
end
|
|
end
|