Sha256: c5c8ca7d5ce0974d9eff03a373cb59aeed950d0a912edb13d61731385aae8133

Contents?: true

Size: 1.51 KB

Versions: 60

Compression:

Stored size: 1.51 KB

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Persistence
      module ClassMethods
        def connection(mongo_connection=nil)
          assert_supported
          if mongo_connection.nil?
            @connection ||= MongoMapper.connection
          else
            @connection = mongo_connection
          end
          @connection
        end

        def set_database_name(name)
          assert_supported
          @database_name = name
        end

        def database_name
          assert_supported
          @database_name
        end

        def database
          assert_supported
          if database_name.nil?
            MongoMapper.database
          else
            connection.db(database_name)
          end
        end

        def set_collection_name(name)
          assert_supported
          @collection_name = name
        end

        def collection_name
          assert_supported
          @collection_name ||= self.to_s.tableize.gsub(/\//, '.')
        end

        def collection
          assert_supported
          database.collection(collection_name)
        end

        private
          def assert_supported
            if embeddable?
              raise NotSupported.new('This is not supported for embeddable documents at this time.')
            end
          end
      end

      module InstanceMethods
        def collection
          _root_document.class.collection
        end

        def database
          _root_document.class.database
        end
      end
    end
  end
end

Version data entries

60 entries across 60 versions & 7 rubygems

Version Path
jonbell-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/persistence.rb
ign-mongo_mapper-0.8.6.2 lib/mongo_mapper/plugins/persistence.rb
ign-mongo_mapper-0.8.6.1 lib/mongo_mapper/plugins/persistence.rb
ssherman-mongo_mapper-0.8.6 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-0.8.6 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-0.8.5 lib/mongo_mapper/plugins/persistence.rb
honkster-mongo_mapper-0.8.4 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-0.8.4 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/plugins/persistence.rb
mongo_mapper-0.8.3 lib/mongo_mapper/plugins/persistence.rb