Parent

Files

Class/Module Index [+]

Quicksearch

ActiveRecord::DynamicFinderMatch

Active Record Dynamic Finder Match

Refer to ActiveRecord::Base documentation for Dynamic attribute-based finders for detailed info

Attributes

attribute_names[R]
finder[R]
instantiator[R]

Public Class Methods

match(method) click to toggle source
# File 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
new(finder, instantiator, bang, attribute_names) click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 35
def initialize(finder, instantiator, bang, attribute_names)
  @finder          = finder
  @instantiator    = instantiator
  @bang            = bang
  @attribute_names = attribute_names
end

Public Instance Methods

bang?() click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 56
def bang?
  @bang
end
creator?() click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 52
def creator?
  @finder == :first && @instantiator == :create
end
finder?() click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 44
def finder?
  @finder && !@instantiator
end
instantiator?() click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 48
def instantiator?
  @finder == :first && @instantiator
end
save_method() click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 64
def save_method
  bang? ? :save! : :save
end
save_record?() click to toggle source
# File lib/active_record/dynamic_finder_match.rb, line 60
def save_record?
  @instantiator == :create
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.