Sha256: 3fc02fee55f0754756bd333d30734a1b7dd1e4d79582f8ab7cf5c13ce86a568c

Contents?: true

Size: 1.04 KB

Versions: 75

Compression:

Stored size: 1.04 KB

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module DynamicQuerying
      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

        def raise?
          bang == true
        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
  end
end

Version data entries

75 entries across 75 versions & 9 rubygems

Version Path
mongo_mapper-unstable-2010.08.02 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.08.01 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.31 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.30 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.29 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.28 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.27 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
thorsson-mongo_mapper-0.8.2 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.26 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.23 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.21 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.20 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.19 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.18 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.16 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.15 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.14 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.13 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.12 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb
mongo_mapper-unstable-2010.07.09 lib/mongo_mapper/plugins/dynamic_querying/dynamic_finder.rb