Class: Rails::DataMapper::Storage
- Inherits:
-
Object
- Object
- Rails::DataMapper::Storage
show all
- Defined in:
- lib/dm-rails/storage.rb
Defined Under Namespace
Classes: Mysql, Postgres, Sqlite
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, config) ⇒ Storage
Returns a new instance of Storage.
65
66
67
|
# File 'lib/dm-rails/storage.rb', line 65
def initialize(name, config)
@name, @config = name.to_sym, config
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9
10
11
|
# File 'lib/dm-rails/storage.rb', line 9
def config
@config
end
|
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/dm-rails/storage.rb', line 9
def name
@name
end
|
Class Method Details
.create_all ⇒ Object
11
12
13
|
# File 'lib/dm-rails/storage.rb', line 11
def self.create_all
with_local_repositories { |config| create_environment(config) }
end
|
.create_environment(config) ⇒ Object
19
20
21
|
# 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 ⇒ Object
15
16
17
|
# File 'lib/dm-rails/storage.rb', line 15
def self.drop_all
with_local_repositories { |config| drop_environment(config) }
end
|
.drop_environment(config) ⇒ Object
23
24
25
|
# 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) ⇒ Object
27
28
29
30
31
32
33
34
|
# 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
|
Instance Method Details
#_create ⇒ Object
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
106
107
108
|
# File 'lib/dm-rails/storage.rb', line 106
def _create
true
end
|
#_drop ⇒ Object
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
115
116
117
|
# File 'lib/dm-rails/storage.rb', line 115
def _drop
true
end
|
#charset ⇒ Object
89
90
91
|
# File 'lib/dm-rails/storage.rb', line 89
def charset
@charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
end
|
#create ⇒ Object
69
70
71
|
# File 'lib/dm-rails/storage.rb', line 69
def create
puts create_message if _create
end
|
#create_message ⇒ Object
93
94
95
|
# File 'lib/dm-rails/storage.rb', line 93
def create_message
"[datamapper] Created database '#{database}'"
end
|
#database ⇒ Object
77
78
79
|
# File 'lib/dm-rails/storage.rb', line 77
def database
@database ||= config['database'] || config['path']
end
|
#drop ⇒ Object
73
74
75
|
# File 'lib/dm-rails/storage.rb', line 73
def drop
puts drop_message if _drop
end
|
#drop_message ⇒ Object
97
98
99
|
# File 'lib/dm-rails/storage.rb', line 97
def drop_message
"[datamapper] Dropped database '#{database}'"
end
|
#password ⇒ Object
85
86
87
|
# File 'lib/dm-rails/storage.rb', line 85
def password
@password ||= config['password'] || ''
end
|
#username ⇒ Object
81
82
83
|
# File 'lib/dm-rails/storage.rb', line 81
def username
@username ||= config['username'] || ''
end
|