Sha256: 5e9723137c6fa4cf65f045f86230ecf97fde5826c5d5791f67a7364c5bf017db

Contents?: true

Size: 946 Bytes

Versions: 1

Compression:

Stored size: 946 Bytes

Contents

require_relative 'persistence'

module ArisControl
  class Bookkeeper
    attr_reader :persistence, :apps

    def initialize(persistence = default_persistence)
      @persistence = persistence
      @apps = persistence.load_apps
    end

    def list
      apps
    end

    def add(name, opts = {})
      env_vars = opts[:env_vars]
      app = apps[name] || {}
      apps[name] = app.dup.tap do |h|
        h['email']    = opts[:email] || app.fetch('email')
        h['ssh_key']  = opts[:ssh_key] if opts[:ssh_key]
        h['env_vars'] = with_upcased_keys(env_vars) if env_vars
      end
      persistence.store_apps(apps)
    end

    def delete(name)
      apps.delete(name)
      persistence.store_apps(apps)
    end

    def default_persistence
      ArisControl::Persistence.new
    end

    private

    def with_upcased_keys(hash)
      hash or return
      hash.each_with_object({}) {|(k,v),h| h[k.to_s.upcase] = v }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
aris-control-3.2.0 lib/aris-control/bookkeeper.rb