class Rails::DataMapper::Configuration

Attributes

raw[RW]
root[RW]

Public Class Methods

create() click to toggle source
# File lib/dm-rails/configuration.rb, line 14
def self.create
  Rails::DataMapper.configuration ||= new
end

Public Instance Methods

environments() click to toggle source
# File lib/dm-rails/configuration.rb, line 18
def environments
  raw.keys
end
field_naming_convention() click to toggle source
# File lib/dm-rails/configuration.rb, line 38
def field_naming_convention
  @field_naming_convention ||= {}
end
repositories() click to toggle source
# File lib/dm-rails/configuration.rb, line 22
def repositories
  @repositories ||= raw.reject { |k,v| k =~ /defaults/ }.inject({}) do |repositories, pair|
    environment, config = pair.first, pair.last
    repositories[environment] = begin
      c = config['repositories'] || {}
      c['default'] ||= config.except('repositories') if config.except('repositories')
      normalize_repository_config(c)
    end
    repositories
  end
end
resource_naming_convention() click to toggle source
# File lib/dm-rails/configuration.rb, line 34
def resource_naming_convention
  @resource_naming_convention ||= {}
end

Private Instance Methods

normalize_repository_config(hash) click to toggle source
# File lib/dm-rails/configuration.rb, line 44
def normalize_repository_config(hash)
  config = {}
  hash.each do |key, value|

    config[key] = if value.kind_of?(Hash)
      normalize_repository_config(value)
    elsif key == 'port'
      value.to_i
    elsif key == 'adapter' && value == 'postgresql'
      'postgres'
    elsif (key == 'database' || key == 'path') && hash['adapter'] =~ /sqlite/
      value == ':memory:' ? value : File.expand_path(hash[key], root)
    else
      value
    end

    # FIXME Rely on a new dm-sqlite-adapter to do the right thing
    # For now, we need to make sure that both 'path' and 'database'
    # point to the same thing, since dm-sqlite-adapter always passes
    # both to the underlying do_sqlite3 adapter and there's no
    # guarantee which one will be used

    config['path']     = config[key] if key == 'database'
    config['database'] = config[key] if key == 'path'

  end
  config
end