Sha256: 37ed51441058a4c8333b2bb1eca7aae89c5cb49d041017906cdd7607f410a88e
Contents?: true
Size: 791 Bytes
Versions: 3
Compression:
Stored size: 791 Bytes
Contents
# frozen_string_literal: true require 'yaml' module LightTr class Store def initialize(name:, file_name: nil, file_path: nil) @name = name file_name ||= "#{name.to_s.downcase}.yml" file_path ||= file_path || Dir.pwd @file = File.join(file_path, file_name) end attr_reader :name, :file def current YAML.safe_load(File.read(file)) || {} rescue StandardError => _e {} end def load(target, query) (current[target] || {})[query.downcase] end def save(target, query, translation) payload = current.merge( target => (current[target] || {}).merge( query.downcase => translation ) ) File.open(file, 'w') { |f| YAML.dump(payload, f) } translation end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
light_tr-2.0.1 | lib/light_tr/store.rb |
light_tr-2.0.0 | lib/light_tr/store.rb |
light_tr-1.0.0 | lib/light_tr/store.rb |