Class: Rails::DataMapper::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/dm-rails/storage.rb

Direct Known Subclasses

Mysql, Postgres, Sqlite

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

#configObject (readonly)

Returns the value of attribute config.



9
10
11
# File 'lib/dm-rails/storage.rb', line 9

def config
  @config
end

#nameObject (readonly)

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_allObject



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_allObject



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

#_createObject

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

#_dropObject

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

#charsetObject



89
90
91
# File 'lib/dm-rails/storage.rb', line 89

def charset
  @charset ||= config['charset'] || ENV['CHARSET'] || 'utf8'
end

#createObject



69
70
71
# File 'lib/dm-rails/storage.rb', line 69

def create
  puts create_message if _create
end

#create_messageObject



93
94
95
# File 'lib/dm-rails/storage.rb', line 93

def create_message
  "[datamapper] Created database '#{database}'"
end

#databaseObject



77
78
79
# File 'lib/dm-rails/storage.rb', line 77

def database
  @database ||= config['database'] || config['path']
end

#dropObject



73
74
75
# File 'lib/dm-rails/storage.rb', line 73

def drop
  puts drop_message if _drop
end

#drop_messageObject



97
98
99
# File 'lib/dm-rails/storage.rb', line 97

def drop_message
  "[datamapper] Dropped database '#{database}'"
end

#passwordObject



85
86
87
# File 'lib/dm-rails/storage.rb', line 85

def password
  @password ||= config['password'] || ''
end

#usernameObject



81
82
83
# File 'lib/dm-rails/storage.rb', line 81

def username
  @username ||= config['username'] || ''
end