Class: RubybenchRunner::Configurations
- Inherits:
-
Object
- Object
- RubybenchRunner::Configurations
- Defined in:
- lib/rubybench_runner/configurations.rb
Constant Summary collapse
- CONFIG_PATH =
File.join(Dir.home, ".rubybench_runner_config")
- CONFIG_VERSION =
1- MYSQL_MAPPING =
{ user: :username, dbname: :database }
- DEFAULTS =
{ postgres: { user: nil, dbname: "rubybench", host: nil, port: nil, password: nil }, mysql2: { user: nil, dbname: "rubybench", host: nil, port: nil, password: nil }, config_version: CONFIG_VERSION }
Instance Method Summary collapse
- #[](key) ⇒ Object
- #config ⇒ Object
- #config_changed? ⇒ Boolean
-
#initialize(mysql_map: false) ⇒ Configurations
constructor
A new instance of Configurations.
Constructor Details
#initialize(mysql_map: false) ⇒ Configurations
Returns a new instance of Configurations.
26 27 28 29 30 31 |
# File 'lib/rubybench_runner/configurations.rb', line 26 def initialize(mysql_map: false) @mysql_map = mysql_map if !File.exists?(CONFIG_PATH) File.write(CONFIG_PATH, YAML.dump(DEFAULTS)) end end |
Instance Method Details
#[](key) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/rubybench_runner/configurations.rb', line 33 def [](key) key = key.to_s result = config key.split(".").each do |k| result = result[k] || result[k.to_sym] end result end |
#config ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rubybench_runner/configurations.rb', line 42 def config content = File.read(CONFIG_PATH) if content != @content @content = content @parsed = YAML.load(@content) if @mysql_map MYSQL_MAPPING.each do |old, new| next if !@parsed[:mysql2].key?(old) val = @parsed[:mysql2][old] @parsed[:mysql2][new] = val @parsed[:mysql2].delete(old) end end end @parsed end |
#config_changed? ⇒ Boolean
59 60 61 |
# File 'lib/rubybench_runner/configurations.rb', line 59 def config_changed? File.read(CONFIG_PATH) != YAML.dump(DEFAULTS) end |