Class: Merb::Orms::DataMapper::Connect

Inherits:
BootLoader
  • Object
show all
Defined in:
lib/merb_datamapper.rb

Class Method Summary collapse

Class Method Details

.runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/merb_datamapper.rb', line 38

def self.run
  Merb.logger.verbose! "Merb::Orms::DataMapper::Connect block."

  # check for the presence of database.yml
  if File.file?(Merb.dir_for(:config) / "database.yml")
    # if we have it, connect
    Merb::Orms::DataMapper.connect
  else
    # assume we'll be told at some point
    Merb.logger.info "No database.yml file found in #{Merb.dir_for(:config)}, assuming database connection(s) established in the environment file in #{Merb.dir_for(:config)}/environments"
  end

  # if we use a datamapper session store, require it.
  Merb.logger.verbose! "Checking if we need to use DataMapper sessions"
  if Merb::Config.session_store == 'datamapper'
    Merb.logger.verbose! "Using DataMapper sessions"
    require "merb_datamapper/data_mapper_session"
  end

  # take advantage of the fact #id returns the key of the model, unless #id is a property
  Merb::Router.root_behavior = Merb::Router.root_behavior.identify(DataMapper::Resource => :id)

  Merb.logger.verbose! "Merb::Orms::DataMapper::Connect complete"
end