Class: Litterbox::Habitat::Profiles

Inherits:
Object
  • Object
show all
Defined in:
lib/litterbox/profiles/profiles.rb

Overview

Habitat Profile

Class Method Summary collapse

Class Method Details

.env(profile) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/litterbox/profiles/profiles.rb', line 22

def self.env(profile)
  cmd = ''
  cmd << "export HAB_BLDR_URL=\"#{profile['bldr_url']}\"\n" if profile['bldr_url']
  cmd << "export HAB_AUTH_TOKEN=\"#{profile['auth_token']}\"\n" if profile['auth_token']
  cmd << "export HAB_ORIGIN=\"#{profile['origin']}\"\n" if profile['origin']
  cmd
end

.read(config = "#{ENV['HOME']}/.litterbox") ⇒ Object



15
16
17
18
19
20
# File 'lib/litterbox/profiles/profiles.rb', line 15

def self.read(config = "#{ENV['HOME']}/.litterbox")
  unless File.exist?(config)
    # Create it
  end
  TOML::Parser.new(File.read(config)).parsed
end

.set(profile, file = "#{ENV['HOME']}/.litterbox") ⇒ Object



7
8
9
10
11
12
13
# File 'lib/litterbox/profiles/profiles.rb', line 7

def self.set(profile, file = "#{ENV['HOME']}/.litterbox")
  config = read file
  config['profile'] = profile
  doc = TOML::Generator.new(config).body
  File.write(file, doc)
  env config[profile]
end