Sha256: 5d1b3e34db392d466c33a7c23be83bef2456e14595ae6961aef4e3ef27f50b52

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'yao'
require 'yaml'

module Kaname
  class Config
    def self.setup
      load_config
      setup_yao
    end

    def self.username
      @@username
    end

    def self.management_url
      @@management_url
    end

    private

    def self.load_config
      config_file = File.join(Dir.home, '.kaname')
      raise '~/.kaname is missing' unless File.exists?(config_file)

      config = YAML.load_file(config_file)

      %w[auth_url tenant username password].each do |conf_item|
        raise "Configuration '#{conf_item}' is missing. Check your ~/.kaname" unless config[conf_item]
      end

      @@auth_url       = config['auth_url']
      @@tenant         = config['tenant']
      @@username       = config['username']
      @@password       = config['password']
      @@management_url = config['management_url']
      true
    end

    def self.setup_yao
      Yao.configure do
        auth_url    @@auth_url
        tenant_name @@tenant
        username    @@username
        password    @@password
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kaname-0.5.1 lib/kaname/config.rb
kaname-0.5.0 lib/kaname/config.rb
kaname-0.4.0 lib/kaname/config.rb