Module: Rails::DataMapper

Defined in:
lib/dm-rails/setup.rb,
lib/dm-rails/railtie.rb,
lib/dm-rails/storage.rb,
lib/dm-rails/configuration.rb,
lib/dm-rails/session_store.rb,
lib/dm-rails/railties/i18n_support.rb,
lib/dm-rails/middleware/identity_map.rb,
lib/dm-rails/multiparameter_attributes.rb,
lib/dm-rails/railties/controller_runtime.rb

Defined Under Namespace

Modules: I18nSupport, Middleware, MultiparameterAttributes, Railties Classes: Configuration, MultiparameterAssignmentError, MultiparameterAssignmentErrors, Railtie, SessionStore, Storage

Class Method Summary collapse

Class Method Details

.finalizeObject



54
55
56
# File 'lib/dm-rails/setup.rb', line 54

def self.finalize
  ::DataMapper.finalize
end

.preload_models(app) ⇒ Object



58
59
60
61
62
63
# File 'lib/dm-rails/setup.rb', line 58

def self.preload_models(app)
  app.config.paths['app/models'].each do |path|
    Dir.glob("#{path}/**/*.rb").sort.each { |file| require_dependency file[path.length..-1] }
  end
  finalize
end

.setup(environment) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/dm-rails/setup.rb', line 9

def self.setup(environment)
  ::DataMapper.logger.info "[datamapper] Setting up the #{environment.inspect} environment:"
  configuration.repositories[environment].each do |name, config|
    setup_with_instrumentation(name.to_sym, config)
  end
  finalize
end

.setup_log_listener(adapter_name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dm-rails/setup.rb', line 41

def self.setup_log_listener(adapter_name)
  adapter_name = 'sqlite3' if adapter_name == 'sqlite'
  driver_name  = ActiveSupport::Inflector.camelize(adapter_name)

  setup_do_driver(driver_name) do |driver|
    DataObjects::Connection.send(:include, LogListener)
    # FIXME Setting DataMapper::Logger.new($stdout, :off) alone won't work because the #log
    # method is currently only available in DO and needs an explicit DO Logger instantiated.
    # We turn the logger :off because ActiveSupport::Notifications handles displaying log messages
    driver.logger = DataObjects::Logger.new($stdout, :off)
  end
end

.setup_logger(logger) ⇒ Object



37
38
39
# File 'lib/dm-rails/setup.rb', line 37

def self.setup_logger(logger)
  ::DataMapper.logger = logger
end

.setup_with_instrumentation(name, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dm-rails/setup.rb', line 17

def self.setup_with_instrumentation(name, options)

  adapter = if options['uri']
              database_uri = ::Addressable::URI.parse(options['uri'])
              ::DataMapper.logger.info "[datamapper] Setting up #{name.inspect} repository: '#{database_uri.path}' on #{database_uri.scheme}"
              ::DataMapper.setup(name, database_uri)
            else
              ::DataMapper.logger.info "[datamapper] Setting up #{name.inspect} repository: '#{options['database']}' on #{options['adapter']}"
             ::DataMapper.setup(name, options)
            end

  if convention = configuration.resource_naming_convention[name]
    adapter.resource_naming_convention = convention
  end
  if convention = configuration.field_naming_convention[name]
    adapter.field_naming_convention = convention
  end
  setup_log_listener(adapter.options['adapter'])
end

.storageObject



4
5
6
# File 'lib/dm-rails/storage.rb', line 4

def self.storage
  Storage
end