Module: Phenix

Extended by:
Phenix
Included in:
Phenix
Defined in:
lib/phenix.rb,
lib/phenix/version.rb

Constant Summary collapse

CONFIG_TO_MYSQL_MAPPING =
{
  'username' => 'user',
  'password' => 'password',
  'port' => 'port',
  'host' => 'host'
}.freeze
VERSION =
'0.4.0'

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.current_configurationObject

Returns the value of attribute current_configuration.



15
16
17
# File 'lib/phenix.rb', line 15

def current_configuration
  @current_configuration
end

.database_config_pathObject

Returns the value of attribute database_config_path.



14
15
16
# File 'lib/phenix.rb', line 14

def database_config_path
  @database_config_path
end

.schema_pathObject

Returns the value of attribute schema_path.



14
15
16
# File 'lib/phenix.rb', line 14

def schema_path
  @schema_path
end

.skip_databaseObject

Returns the value of attribute skip_database.



14
15
16
# File 'lib/phenix.rb', line 14

def skip_database
  @skip_database
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Phenix)

    the object that the method was called on



17
18
19
20
21
22
23
# File 'lib/phenix.rb', line 17

def configure
  self.database_config_path = File.join(Dir.pwd, 'test', 'database.yml')
  self.schema_path          = File.join(Dir.pwd, 'test', 'schema.rb')
  self.skip_database        = ->(_, _) { false }

  yield(self) if block_given?
end

Instance Method Details

#burn!Object



32
33
34
# File 'lib/phenix.rb', line 32

def burn!
  drop_databases
end

#load_database_config(config_path = Phenix.database_config_path) ⇒ Object



36
37
38
39
40
# File 'lib/phenix.rb', line 36

def load_database_config(config_path = Phenix.database_config_path)
  erb_config = IO.read(config_path)
  yaml_config = ERB.new(erb_config).result
  ActiveRecord::Base.configurations = Phenix.current_configuration = YAML.load(yaml_config)
end

#rise!(with_schema: true, config_path: Phenix.database_config_path) ⇒ Object



26
27
28
29
30
# File 'lib/phenix.rb', line 26

def rise!(with_schema: true, config_path: Phenix.database_config_path)
  load_database_config(config_path)
  drop_databases
  create_databases(with_schema)
end