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, Mysql2, 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.



65
66
67
# File 'lib/sequel-rails/storage.rb', line 65

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/sequel-rails/storage.rb', line 10

def config
  @config
end

Class Method Details

.create_allObject



12
13
14
# File 'lib/sequel-rails/storage.rb', line 12

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

.create_environment(config) ⇒ Object



20
21
22
# File 'lib/sequel-rails/storage.rb', line 20

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

.drop_allObject



16
17
18
# File 'lib/sequel-rails/storage.rb', line 16

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

.drop_environment(config) ⇒ Object



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

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

.new(config) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/sequel-rails/storage.rb', line 28

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



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

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

#createObject



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

def create
  _create
  puts "[sequel] Created database '#{database}'"
end

#databaseObject



80
81
82
# File 'lib/sequel-rails/storage.rb', line 80

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

#dropObject



74
75
76
77
78
# File 'lib/sequel-rails/storage.rb', line 74

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

#hostObject



92
93
94
# File 'lib/sequel-rails/storage.rb', line 92

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

#ownerObject



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

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

#passwordObject



88
89
90
# File 'lib/sequel-rails/storage.rb', line 88

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

#portObject



96
97
98
# File 'lib/sequel-rails/storage.rb', line 96

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

#usernameObject



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

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