Module: MongoDoc::Connection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#config_pathObject



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

def config_path
  @config_path || './mongodb.yml'
end

#default_nameObject



27
28
29
# File 'lib/mongo_doc/connection.rb', line 27

def default_name
  @default_name ||= "mongo_doc"
end

#envObject



31
32
33
# File 'lib/mongo_doc/connection.rb', line 31

def env
  @env ||= 'development'
end

#hostObject



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

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

#nameObject



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

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

#optionsObject



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

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

#portObject



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

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

#strictObject



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

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

Instance Method Details

#configurationObject



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

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

#connectionObject



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

def connection
  @connection ||= connect
end

#databaseObject



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

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