Sha256: 50a241338e60b5ef9d14ee40b3691addbf680ca55ff587f00bbf6173c149fa42
Contents?: true
Size: 908 Bytes
Versions: 106
Compression:
Stored size: 908 Bytes
Contents
require "fileutils" require "yaml" module CC module CLI class FileStore # This class is not supposed to be directly used. It should be sublcassed # and a few constants need to be defined on the sublass to be usable. # # FILE_NAME is the name of the file this class wraps. def initialize load_data end def save return false unless File.exist? self.class::FILE_NAME File.open(self.class::FILE_NAME, "w") do |f| YAML.dump data, f end true end private attr_reader :data def load_data @data = if File.exist? self.class::FILE_NAME File.open(self.class::FILE_NAME, "r:bom|utf-8") do |f| YAML.safe_load(f, [Time], [], false, self.class::FILE_NAME) || {} end else {} end end end end end
Version data entries
106 entries across 106 versions & 2 rubygems