require 'yaml' module MissingTranslation class Configuration attr_accessor :config FILE_NAME = "missing_translation.yml" def self.file_exists? File.exist?(FILE_NAME) end def self.create_file File.open(FILE_NAME, 'w+') do |f| f.flock(File::LOCK_EX) f.rewind f.write({ key: nil, locale_prefix: true }.to_yaml) f.flush end end def self.write_config(config) File.open(FILE_NAME, "w+") do |f| f.flock(File::LOCK_EX) f.truncate(0) f.write(config.to_hash.to_yaml) f.flush end end def initialize @file = File.open(FILE_NAME) unless @file puts "Configuration file does not exist" return end @config = (YAML.load(@file.read) || { key: nil }) end def update_key(key) @config[:key] = key self.class.write_config(@config) end end end