Class: DbEntropy::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/db-entropy/base.rb

Direct Known Subclasses

Mongoid, Mysql, Mysql2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(extra_envs = ENV['EXTRA_ENVS']) ⇒ Base

Returns a new instance of Base.



5
6
7
8
# File 'lib/db-entropy/base.rb', line 5

def initialize(extra_envs=ENV['EXTRA_ENVS'])
  extra_envs ||= ''
  @extra_environments = extra_envs.split(',').uniq.compact
end

Instance Attribute Details

#extra_environmentsObject

Returns the value of attribute extra_environments.



3
4
5
# File 'lib/db-entropy/base.rb', line 3

def extra_environments
  @extra_environments
end

Instance Method Details

#generate_random_name(length = 10) ⇒ Object



10
11
12
# File 'lib/db-entropy/base.rb', line 10

def generate_random_name(length=10)
  rand(32**length).to_s(32)
end

#generate_yaml(path) ⇒ Object



14
15
16
17
# File 'lib/db-entropy/base.rb', line 14

def generate_yaml(path)
  config = generate_database_config
  write_to_yaml(config,path)
end

#write_to_yaml(db_config, path) ⇒ Object



19
20
21
# File 'lib/db-entropy/base.rb', line 19

def write_to_yaml(db_config,path)
  File.open(path, 'w+') { |out| YAML.dump(db_config, out) }
end