Module: MongoDoc::Connection

Extended by:
Connection
Included in:
Connection
Defined in:
lib/mongodoc/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_pathObject



11
12
13
# File 'lib/mongodoc/connection.rb', line 11

def config_path
  @config_path || default_path
end

#envObject



27
28
29
30
31
32
33
# File 'lib/mongodoc/connection.rb', line 27

def env
  if rails?
    Rails.env
  else
    @env ||= 'development'
  end
end

#hostObject



35
36
37
# File 'lib/mongodoc/connection.rb', line 35

def host
  @host ||= configuration['host']
end

#nameObject



39
40
41
# File 'lib/mongodoc/connection.rb', line 39

def name
  @name ||= configuration['name'] || default_name
end

#optionsObject



43
44
45
# File 'lib/mongodoc/connection.rb', line 43

def options
  @options ||= configuration['options'] || {}
end

#portObject



47
48
49
# File 'lib/mongodoc/connection.rb', line 47

def port
  @port ||= configuration['port']
end

#strictObject



51
52
53
# File 'lib/mongodoc/connection.rb', line 51

def strict
  @strict ||= configuration['strict'] || false
end

Instance Method Details

#configurationObject



15
16
17
# File 'lib/mongodoc/connection.rb', line 15

def configuration
  @configuration ||= File.exists?(config_path) ? YAML.load_file(config_path)[env] : {}
end

#connectionObject



19
20
21
# File 'lib/mongodoc/connection.rb', line 19

def connection
  @connection ||= connect
end

#databaseObject



23
24
25
# File 'lib/mongodoc/connection.rb', line 23

def database
  @database ||= connection.db(name, :strict => strict)
end