Class: MapReduced::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/map_reduced/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.template_pathObject



32
33
34
35
# File 'lib/map_reduced/config.rb', line 32

def template_path
  return @template_path if defined?(@template_path)
  defined?(Rails) ? Rails.root + "app/functions" : Pathname.new(File.expand_path("./functions"))
end

Class Method Details

.database=(string) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/map_reduced/config.rb', line 7

def database=(string)
  begin
    if string.match /^.+\:\/\/.+/
      uri = URI.parse(string)
      connection = Mongo::Connection.new(uri.host, uri.port)
      database = uri.path.gsub(/^\//, "")
      if uri.user && uri.password
        connection.add_auth(database, uri.user, uri.password) 
        connection.apply_saved_authentication
      end
      @db = connection.db(database)
    else
      @db = Mongo::Connection.new.db(string)
    end
  rescue Mongo::ConnectionFailure => e
    raise Mongo::ConnectionFailure, "#{e}\nIt is possible that your database string is badly formed.\nIt should either be a database name (for localhost connections), or a fully-formed remote connection like mongodb://user:pass@host:port/database"
  end
  
end

.dbObject



27
28
29
30
# File 'lib/map_reduced/config.rb', line 27

def db
  warn "Tell MapReduced which database to use, like this:\nMapReduced::Config.database = 'my_awesome_database'" unless defined? @db
  @db
end