Sha256: 85360ad02761bb7429c3545fefd097e9efca99f1486d0d1e88ff04b29b48e8e4
Contents?: true
Size: 789 Bytes
Versions: 4
Compression:
Stored size: 789 Bytes
Contents
require 'yaml' require 'pathname' module ArisControl class Persistence attr_reader :users_file_path def initialize(users_file_path = default_users_file_path) @users_file_path = Pathname.new(users_file_path) end def store_users(users) users ||= {} IO.binwrite(users_file_path, serialized_users(users)) users end def load_users store_users({}) unless users_file_path.exist? deserialized_users(IO.binread(users_file_path)) end def default_users_file_path '/opt/aris/config/users.yml' end private def serialized_users(users) YAML.dump({ 'aris_users' => users }) end def deserialized_users(string) yaml = YAML.load(string) || {} yaml['aris_users'] || {} end end end
Version data entries
4 entries across 4 versions & 1 rubygems