Class: RubyPitaya::DatabaseConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/core/database_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(setup) ⇒ DatabaseConfig

Returns a new instance of DatabaseConfig.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rubypitaya/core/database_config.rb', line 10

def initialize(setup)
  @config = {
    'adapter' => 'postgresql',
    'encoding' => 'unicode',
    'pool' => setup.fetch('rubypitaya.database.pool', 5),
    'host' => setup['rubypitaya.database.host'],
    'port' => setup['rubypitaya.database.port'],
    'user' => setup['rubypitaya.database.user'],
    'password' => setup['rubypitaya.database.password'],
    'database' => setup['rubypitaya.database.name'],
  }

  environment_name = setup.fetch('rubypitaya.server.environment', 'development')

  @config['database'] = "#{@config['database']}_test" if environment_name == 'test'
end

Instance Method Details

#configObject



27
28
29
# File 'lib/rubypitaya/core/database_config.rb', line 27

def config
  @config
end

#connection_dataObject



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubypitaya/core/database_config.rb', line 31

def connection_data
  {
    'adapter': config['adapter'],
    'encoding': config['encoding'],
    'pool': config['pool'],
    'host': config['host'],
    'port': config['port'],
    'user': config['user'],
    'password': config['password'],
    'database': config['database'],
  }
end

#connection_data_without_databaseObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rubypitaya/core/database_config.rb', line 44

def connection_data_without_database
  {
    'adapter': config['adapter'],
    'encoding': config['encoding'],
    'pool': config['pool'],
    'host': config['host'],
    'port': config['port'],
    'user': config['user'],
    'password': config['password'],
  }
end

#database_nameObject



56
57
58
# File 'lib/rubypitaya/core/database_config.rb', line 56

def database_name
  config['database']
end