Sha256: 55e96a87603d4050332460bf98ce608f04e36ccc53c468953883219e6d952e72

Contents?: true

Size: 937 Bytes

Versions: 3

Compression:

Stored size: 937 Bytes

Contents

module DatabaseCleaner
  class ORMAutodetector
    ORMS = {
      active_record: "ActiveRecord",
      data_mapper: "DataMapper",
      mongo_mapper: "MongoMapper",
      mongoid: "Mongoid",
      mongo: "Mongo",
      couch_potato: "CouchPotato",
      sequel: "Sequel",
      moped: "Moped",
      ohm: "Ohm",
      redis: "Redis",
      neo4j: "Neo4j",
    }

    def orm
      @autodetected = true
      autodetected_orm or raise no_orm_detected_error
      ORMS.key(autodetected_orm.to_s)
    end

    def autodetected?
      !!@autodetected
    end

    private

    def autodetected_orm
      ORMS.values.find do |orm|
        Kernel.const_get(orm) rescue next
      end
    end

    def no_orm_detected_error
      orm_list = ORMS.values.join(", ").sub(ORMS.values.last, "or #{ORMS.values.last}")
      NoORMDetected.new("No known ORM was detected!  Is #{orm_list} loaded?")
    end
  end
  private_constant :ORMAutodetector
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
database_cleaner-1.99.0 lib/database_cleaner/orm_autodetector.rb
database_cleaner-1.99.0.beta lib/database_cleaner/orm_autodetector.rb
database_cleaner-1.8.5 lib/database_cleaner/orm_autodetector.rb