class Rails::DataMapper::Storage
Attributes
config[R]
name[R]
Public Class Methods
create_all()
click to toggle source
# File lib/dm-rails/storage.rb, line 11 def self.create_all with_local_repositories { |config| create_environment(config) } end
create_environment(config)
click to toggle source
# File lib/dm-rails/storage.rb, line 19 def self.create_environment(config) config.each { |repo_name, repo_config| new(repo_name, repo_config).create } end
drop_all()
click to toggle source
# File lib/dm-rails/storage.rb, line 15 def self.drop_all with_local_repositories { |config| drop_environment(config) } end
drop_environment(config)
click to toggle source
# File lib/dm-rails/storage.rb, line 23 def self.drop_environment(config) config.each { |repo_name, repo_config| new(repo_name, repo_config).drop } end
new(name, config)
click to toggle source
Calls superclass method
# File lib/dm-rails/storage.rb, line 27 def self.new(name, config) klass = lookup_class(config['adapter']) if klass.equal?(self) super(name, config) else klass.new(name, config) end end
new(name, config)
click to toggle source
# File lib/dm-rails/storage.rb, line 65 def initialize(name, config) @name, @config = name.to_sym, config end
Private Class Methods
lookup_class(adapter)
click to toggle source
# File lib/dm-rails/storage.rb, line 49 def lookup_class(adapter) klass_name = normalized_adapter_name(adapter).camelize.to_sym unless Storage.const_defined?(klass_name) raise "Adapter #{adapter} not supported (#{klass_name.inspect})" end const_get(klass_name) end
normalized_adapter_name(adapter_name)
click to toggle source
# File lib/dm-rails/storage.rb, line 59 def normalized_adapter_name(adapter_name) adapter_name.to_s == 'sqlite3' ? 'sqlite' : adapter_name end
with_local_repositories() { |config| ... }
click to toggle source
# File lib/dm-rails/storage.rb, line 39 def with_local_repositories Rails::DataMapper.configuration.repositories.each_value do |config| if config['host'].blank? || %w[ 127.0.0.1 localhost ].include?(config['host']) yield(config) else puts "This task only modifies local databases. #{config['database']} is on a remote host." end end end
Public Instance Methods
_create()
click to toggle source
Create the configured database
This is a noop so that calling this method won’t explode on people who use adapters that don’t support creating a storage recepticle
# File lib/dm-rails/storage.rb, line 106 def _create true end
_drop()
click to toggle source
Drop the configured database
This is a noop so that calling this method won’t explode on people who use adapters that don’t support dropping a storage recepticle
# File lib/dm-rails/storage.rb, line 115 def _drop true end
charset()
click to toggle source
# File lib/dm-rails/storage.rb, line 89 def charset @charset ||= config['charset'] || ENV['CHARSET'] || 'utf8' end
create()
click to toggle source
# File lib/dm-rails/storage.rb, line 69 def create puts create_message if _create end
create_message()
click to toggle source
# File lib/dm-rails/storage.rb, line 93 def create_message "[datamapper] Created database '#{database}'" end
database()
click to toggle source
# File lib/dm-rails/storage.rb, line 77 def database @database ||= config['database'] || config['path'] end
drop()
click to toggle source
# File lib/dm-rails/storage.rb, line 73 def drop puts drop_message if _drop end
drop_message()
click to toggle source
# File lib/dm-rails/storage.rb, line 97 def drop_message "[datamapper] Dropped database '#{database}'" end
password()
click to toggle source
# File lib/dm-rails/storage.rb, line 85 def password @password ||= config['password'] || '' end
username()
click to toggle source
# File lib/dm-rails/storage.rb, line 81 def username @username ||= config['username'] || '' end