Sha256: 2bc01a7b2bc379da4ad4247b30e7c013496ab19e82fae4f9760a02c1adf57349
Contents?: true
Size: 928 Bytes
Versions: 5
Compression:
Stored size: 928 Bytes
Contents
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
Version data entries
5 entries across 5 versions & 1 rubygems