Class: Rails::Sequel::Storage

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

Direct Known Subclasses

Jdbc, Mysql, Postgres, Sqlite

Defined Under Namespace

Classes: Jdbc, Mysql, Postgres, Sqlite

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Storage

Returns a new instance of Storage.



78
79
80
# File 'lib/sequel-rails/storage.rb', line 78

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



24
25
26
# File 'lib/sequel-rails/storage.rb', line 24

def config
  @config
end

Class Method Details

.create_allObject



26
27
28
# File 'lib/sequel-rails/storage.rb', line 26

def self.create_all
  with_local_repositories { |config| create_environment(config) }
end

.create_environment(config) ⇒ Object



34
35
36
# File 'lib/sequel-rails/storage.rb', line 34

def self.create_environment(config)
  new(config).create
end

.drop_allObject



30
31
32
# File 'lib/sequel-rails/storage.rb', line 30

def self.drop_all
  with_local_repositories { |config| drop_environment(config) }
end

.drop_environment(config) ⇒ Object



38
39
40
# File 'lib/sequel-rails/storage.rb', line 38

def self.drop_environment(config)
  new(config).drop
end

.new(config) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/sequel-rails/storage.rb', line 42

def self.new(config)
  config = Rails::Sequel.configuration.environments[config.to_s] unless config.kind_of?(Hash)

  klass = lookup_class(config['adapter'])
  if klass.equal?(self)
    super(config)
  else
    klass.new(config)
  end
end

Instance Method Details

#charsetObject



124
125
126
# File 'lib/sequel-rails/storage.rb', line 124

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

#createObject



82
83
84
85
86
87
88
# File 'lib/sequel-rails/storage.rb', line 82

def create
  if _create        
    puts "[sequel] Created database '#{database}'"
  else
    puts "[sequel] FAILED to create database '#{database}'"  
  end  
end

#databaseObject



99
100
101
# File 'lib/sequel-rails/storage.rb', line 99

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

#dropObject



90
91
92
93
94
95
96
97
# File 'lib/sequel-rails/storage.rb', line 90

def drop
  ::Sequel::Model.db.disconnect
  if _drop          
    puts "[sequel] Dropped database '#{database}'"
  else
    puts "[sequel] FAILED to drop database '#{database}'"  
  end  
end

#hostObject



111
112
113
# File 'lib/sequel-rails/storage.rb', line 111

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

#ownerObject



119
120
121
# File 'lib/sequel-rails/storage.rb', line 119

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

#passwordObject



107
108
109
# File 'lib/sequel-rails/storage.rb', line 107

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

#portObject



115
116
117
# File 'lib/sequel-rails/storage.rb', line 115

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

#usernameObject



103
104
105
# File 'lib/sequel-rails/storage.rb', line 103

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