Sha256: 1b93aee559144e35af5dc297dd327ac0fab5a7955fbec3f42aba0f9698c30b64

Contents?: true

Size: 835 Bytes

Versions: 22

Compression:

Stored size: 835 Bytes

Contents

module MongoMapper
  class DynamicFinder
    attr_reader :method, :attributes, :finder, :bang, :instantiator

    def initialize(method)
      @method = method
      @finder = :first
      @bang   = false
      match()
    end

    def found?
      @finder.present?
    end

    protected
      def match        
        case method.to_s
          when /^find_(all_by|by)_([_a-zA-Z]\w*)$/
            @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
        
        @attributes = names && names.split('_and_')
      end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
djsun-mongo_mapper-0.5.6.6 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.6.5 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.6.4 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.6.3 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.6.2 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.6.1 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-0.5.6 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.5.3 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-unstable-2009.10.16 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.5.2 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-0.5.5 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-unstable-2009.10.12 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.4.1 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.3.1 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-0.5.4 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-0.5.3 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-unstable-2009.10.11 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.2.1 lib/mongo_mapper/dynamic_finder.rb
mongo_mapper-0.5.2 lib/mongo_mapper/dynamic_finder.rb
djsun-mongo_mapper-0.5.0.1 lib/mongo_mapper/dynamic_finder.rb