Sha256: 72f76627e744c91f26821186e704903e11e05f67ab9750ad2f5ed38d8be8c625

Contents?: true

Size: 751 Bytes

Versions: 4

Compression:

Stored size: 751 Bytes

Contents

require 'yaml'
require 'pathname'

module ArisControl
  class Persistence
    attr_reader :config_file_path, :users_file_path

    def initialize(config = default_config)
      @config = config
      @config_file_path = Pathname.new config[:config_file_path]
      @users_file_path  = Pathname.new config[:users_file_path]
    end

    def store_users(users)
      users ||= {}
      IO.binwrite(users_file_path, YAML.dump(users))
      users
    end

    def load_users
      store_users({}) unless users_file_path.exist?
      YAML.load(IO.binread(users_file_path)) || {}
    end

    def default_config
      {
        config_file_path: '/opt/aris/config/aris.cfg',
        users_file_path:  '/opt/aris/config/users.yml',
      }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aris-control-1.2.1 lib/aris-control/persistence.rb
aris-control-1.1.1 lib/aris-control/persistence.rb
aris-control-1.1.0 lib/aris-control/persistence.rb
aris-control-1.0.0 lib/aris-control/persistence.rb