lib/mongo_doc/connection.rb in mongo_doc-0.6.0 vs lib/mongo_doc/connection.rb in mongo_doc-0.6.1

- old
+ new

@@ -4,14 +4,14 @@ module Connection extend self - attr_writer :config_path, :env, :host, :name, :options, :port, :strict + attr_writer :config_path, :default_name, :env, :host, :name, :options, :port, :strict def config_path - @config_path || default_path + @config_path || './mongodb.yml' end def configuration @configuration ||= File.exists?(config_path) ? YAML.load_file(config_path)[env] : {} end @@ -22,16 +22,16 @@ def database @database ||= connection.db(name, :strict => strict) end + def default_name + @default_name ||= "mongo_doc" + end + def env - if rails? - Rails.env - else - @env ||= 'development' - end + @env ||= 'development' end def host @host ||= configuration['host'] end @@ -57,29 +57,9 @@ def connect connection = Mongo::Connection.new(host, port, options) raise NoConnectionError unless connection verify_server_version(connection) connection - end - - def default_name - if rails? - "#{Rails.root.basename}_#{Rails.env}" - else - "mongo_doc" - end - end - - def default_path - if rails? - Rails.root + 'config/mongodb.yml' - else - './mongodb.yml' - end - end - - def rails? - Object.const_defined?("Rails") end def verify_server_version(connection) raise UnsupportedServerVersionError.new('MongoDoc requires at least mongoDB version 1.4.0') unless connection.server_version >= "1.4.0" end