class Evm::Config

Public Class Methods

new(config_file, defaults = {}) click to toggle source
# File lib/evm/config.rb, line 5
def initialize(config_file, defaults = {})
  @config_file = config_file
  @defaults = defaults
end

Public Instance Methods

[](type) click to toggle source
# File lib/evm/config.rb, line 10
def [](type)
  config[type.to_s] || begin
    default = @defaults.find { |key, value| key.to_s == type.to_s }
    default[1] if default
  end
end
[]=(type, value) click to toggle source
# File lib/evm/config.rb, line 17
def []=(type, value)
  write(config.merge(type.to_s => value))
end

Private Instance Methods

config() click to toggle source
# File lib/evm/config.rb, line 24
def config
  if File.exist?(@config_file)
    contents = File.read(@config_file)
    if contents.empty?
      {}
    else
      JSON.parse(contents)
    end
  else
    {}
  end
end
write(config = {}) click to toggle source
# File lib/evm/config.rb, line 37
def write(config = {})
  File.open(@config_file, 'w') do |file|
    file.write(config.to_json)
  end
end