Sha256: edb0dc81b1b843e2d5fbe14961bf440b745e9a35976aac6cdf6b87cfdeee01ea

Contents?: true

Size: 764 Bytes

Versions: 5

Compression:

Stored size: 764 Bytes

Contents

require 'yaml'
require 'pathname'

module ArisControl
  class Persistence
    attr_reader :apps_file_path

    def initialize(apps_file_path = default_apps_file_path)
      @apps_file_path = Pathname.new(apps_file_path)
    end

    def store_apps(apps)
      apps ||= {}
      IO.binwrite(apps_file_path, serialized_apps(apps))
      apps
    end

    def load_apps
      store_apps({}) unless apps_file_path.exist?
      deserialized_apps(IO.binread(apps_file_path))
    end

    def default_apps_file_path
      '/opt/aris/config/apps.yml'
    end

    private

    def serialized_apps(apps)
      YAML.dump({ 'aris_apps' => apps })
    end

    def deserialized_apps(string)
      yaml = YAML.load(string) || {}
      yaml['aris_apps'] || {}
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
aris-control-3.3.1 lib/aris-control/persistence.rb
aris-control-3.3.0 lib/aris-control/persistence.rb
aris-control-3.2.0 lib/aris-control/persistence.rb
aris-control-3.1.0 lib/aris-control/persistence.rb
aris-control-3.0.1 lib/aris-control/persistence.rb